Managing and creating virtual domains
Managing virtual domains is really easy with ExpressJS. Imagine that you have two or more subdomains, and you want to serve two different web applications. However, you do not want to create a different web server application for each subdomain. In this kind of situation, ExpressJS allows developers to manage virtual domains within a single web server application using vhosthttps://expressjs.com/en/resources/middleware/vhost.html.
vhost is a configurable middleware function that accepts two arguments. The first one is the hostname
. The second argument is the request handler which will be called when the hostname
matches.
The hostname
follows the same rules as route paths do. They can be either a string or a regular expression.
Getting ready
Create a new package.json
file with the following content:
{ "dependencies": { "express": "4.16.3", "vhost": "3.0.2" } }
Then, install the dependencies by opening a terminal and running:
npm...