Vhost's ending in wildcard do not match. Version 3.0.2
MagnusKlingenberg opened this issue · comments
Vhost will not match if the last char is *. making it harder to develop locally.
Ex:
const express = require('express')
const vhost = require('vhost')
// Configuration
const PORT = 3000;
const HOST = "localhost";
const app = express()
const ok = express()
const fail = express()
ok.use('', (req, res, next) => {
res.send('ok found\n')
})
fail.use('', (req, res, next) => {
res.send('fail found\n')
})
app.use(vhost('ok.lvh.me', ok)) //lvh.me will always resolv to 127.0.0.1
app.use(vhost('fail.*', fail)) //This will not match
app.use('', (req, res, next) => {
res.status(404).send('Vhost Not found\n')
})
app.listen(PORT, HOST, () => {
console.log(`Starting Proxy at ${HOST}:${PORT}`);
});
Calling the server will have the following results:
$ curl 'http://ok.lvh.me:3000/' ok found
$ curl 'http://fail.lvh.me:3000/' Vhost Not found
The wildcard syntax used here is the same as SSL certificates: each asterisk only matches one name part.
When hostname is a string it can contain * to match 1 or more characters in that section of the hostname.
You can use a regular expression for you use case.
something like this @MagnusKlingenberg
app.use(vhost('/fail.*$/', fail));