1

Host headers cause a webserver to return a different virtual host based on which DNS name the DNS server resolved to send the browser to the servers ip. Is it possible to build this sort of functionality into a node.js http server between multiple deployed apps?

(Of course you could just use Apache to do this, but can it be done without Apache?)

Community
  • 1
  • 1
leeand00
  • 25,510
  • 39
  • 140
  • 297
  • See https://stackoverflow.com/questions/19254583/how-do-i-host-multiple-node-js-sites-on-the-same-ip-server-with-different-domain – Pete Alvin Nov 24 '17 at 00:16

1 Answers1

3

Yes, you can certainly implement this same behavior in node. The http module only provides a basic server instance with a request callback, but you can expand on that by checking the Host header and then routing the request to the proper application.

If you are using an server framework like express or connect, there is a vhost middleware that will provide this functionality.

loganfsmyth
  • 156,129
  • 30
  • 331
  • 251