node.js - Specifying a subdomain in the route definition in Express -
i'm new expressjs , nodejs in general, need directions on how achieve effect:
app.get('/', 'sub1.domain.com', function(req, res) { res.send("this sub1 response!"); }); app.get('/', 'sub2.domain.com', function(req, res) { res.send("this sub2 response!"); }
so when request sub1.domain.com
first handler reacts , on sub2.domain.com
response second handler. i've read questions on using vhost purpose, i'd more happy if described above worked rather creating multiple server instances in vhost.
a quick , simple solution is:
app.get('/', function(req, res) { var hostname = req.headers.host.split(":")[0]; if(hostname == "sub1.domain.com") res.send("this sub1 response!"); else if(hostname == "sub2.domain.com") res.send("this sub2 response!"); });
reference:
Comments
Post a Comment