I have our first NodeJS server that’s being deployed to a client server along with the rest of the application. I have a few items that need to be configured on a server-specific basis but I’m unable to find any easy way to handle this.
On googling I’ve found a few choices – using a framework that has support built in (too late), setting up a configuration file that can be loaded (would work, but I don’t want to have to worry about keep one config file for each server we have and keeping those out of git).
I’d love to just have node determine what the request domain is (dev.ourdomain vs http://www.ourdomain) and just do a condition. It sounds easy, it likely IS easy, but I’m having trouble finding any way to determine that domain data.
As @drachenstern mentioned, you could use request.headers.host, as in:
but this wouldn’t provide a canonical domain if the request was made using an IP address rather than the server’s name.
A better option might be to use the hostname of the server, as in: