Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koraysels/ada03c38877badf9c63e to your computer and use it in GitHub Desktop.
Save koraysels/ada03c38877badf9c63e to your computer and use it in GitHub Desktop.
When i wanted to het the current hostname of the application in nodejs I always got back ```localhost``` and not the real hostname.. This was because it was behind an Apache webserver :D solution below
var hostname = req.headers['x-forwarded-server'];
if (typeof hostname == "undefined") {
hostname = ( req.headers.host.match(/:/g) ) ? req.headers.host.slice(0, req.headers.host.indexOf(":")) : req.headers.host;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment