Subdomains Node.js

I am trying to run my Node.js website to run on a single instance serving multiple domains. I have my main domain example.com , and then I have admin.example.com and api.example.com , which have all different routes, etc. I am using Express.

So far, I have added two A entries for subdomains, and also added two entries to /var/vhosts in my CentOS field.

 127.0.0.1 api.example.com 127.0.0.1 admin.example.com 127.0.0.1 example.com 

I know that Express has a method express.vhost , so I've tried:

 app.use(express.vhost('api.example.com', require('./lib/subdomains/api'))) app.use(express.vhost('admin.example.com', require('./lib/subdomains/admin'))) 

But it still only serves my main routes, which are imported below. What am I missing?

+6
source share
1 answer

If anyone else finds this question, you might want to check that you are passing the vhost route parameters correctly.

I used:

 app.get('/', function(res, req) { /* Do stuff.. */ } 

When it will be so. The first argument to the req callback function, the second is res .

 app.get('/', function(req, res) { /* Do stuff.. */ } 

Be diligent with the code :)

+9
source

All Articles