O'Reilly logo

Node Web Development by David Herron

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Virtual hosts and request routing

Virtual hosting is a method of hosting multiple domain names on the same IP address. As Basic Server shows, Node is capable of implementing name-based virtual hosting.

In name-based virtual hosting, the HTTP request will include a Host header specifying the domain name:

GET /path/to/request HTTP/1.1
Host: example.com

In Node the req object contains an array named headers which will contain the Host header. As Basic Server demonstrates, virtual hosting is easily implemented by inspecting the headers array and directing the request appropriately to the requested domain.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required