vhost icon indicating copy to clipboard operation
vhost copied to clipboard

Using express vhost behind a reverse proxy

Open domharrington opened this issue 9 years ago • 3 comments

I'm using express vhost behind a reverse proxy and i want to use this module based on the x-forwarded-host header as opposed to the host header that is hardcoded here:

https://github.com/expressjs/vhost/blob/12565d1e88ccd089f2f04f05227f636d3aea6111/index.js#L77

Express 4 supports this by accessing req.hostname directly: http://expressjs.com/en/4x/api.html#req.hostname

Express 3 supports this at req.host: http://expressjs.com/en/3x/api.html#req.host

Is this module still intended to support express v3? Would you accept a pull request that replaces:

https://github.com/expressjs/vhost/blob/12565d1e88ccd089f2f04f05227f636d3aea6111/index.js#L77

with:

var host = req.hostname || req.host

to keep support with both express v3 and v4.

EDIT: I've just re-read the readme again and this would be the only part of this module which adds a direct express dependency. Maybe the code could be:

var host = req.hostname || req.host || req.headers.host

To support express 3/4 and connect servers.

domharrington avatar Dec 07 '16 00:12 domharrington

Thanks +1

roccomuso avatar May 18 '18 13:05 roccomuso

We really need to get the pull request in because people are hitting this issue a lot and the fix is so easy...

Bramzor avatar Mar 05 '19 14:03 Bramzor

I agree, please get to this pull request!

ty-fleming avatar May 31 '21 17:05 ty-fleming