Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vhost's ending in wildcard do not match. Version 3.0.2 #46

Closed
MagnusKlingenberg opened this issue Apr 27, 2021 · 2 comments
Closed

Vhost's ending in wildcard do not match. Version 3.0.2 #46

MagnusKlingenberg opened this issue Apr 27, 2021 · 2 comments
Labels

Comments

@MagnusKlingenberg
Copy link

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

@MagnusKlingenberg MagnusKlingenberg changed the title Vhost's ending in wildcard do not match Vhost's ending in wildcard do not match. Version 3.0.2 Apr 27, 2021
@dougwilson
Copy link
Contributor

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.

@NandoMB
Copy link

NandoMB commented May 11, 2022

something like this @MagnusKlingenberg
app.use(vhost('/fail.*$/', fail));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants