Reputation: 5169
I'm trying to get my Node.js powered site to run on one instance serving multiple domains. I have my main domain, example.com
and then I have admin.example.com
and api.example.com
which all have different routes etc, I'm using Express.
So far I've added two A records for the subdomains, and also added two entries into /var/vhosts
on my CentOS box.
127.0.0.1 api.example.com
127.0.0.1 admin.example.com
127.0.0.1 example.com
I'm aware that Express has a express.vhost
method so I've already tried:
app.use(express.vhost('api.example.com', require('./lib/subdomains/api')))
app.use(express.vhost('admin.example.com', require('./lib/subdomains/admin')))
But that still only serves my main routes which is imported below. What am I missing?
Upvotes: 6
Views: 6128
Reputation: 5169
If anybody else finds this question, you might want to check that you're passing your vhost route parameters the right way around.
I was using:
app.get('/', function(res, req) { /* Do stuff.. */ }
When it should be. The first argument for the callback function is req
, then the second one is res
.
app.get('/', function(req, res) { /* Do stuff.. */ }
Be diligent with your code :)
Upvotes: 9