Subdomains in localhost
RaghavendhraK opened this issue · comments
This is our code
var express = require('express');
var vhost = require('vhost');
var app = express();
app.use(vhost('mail.example.com', function(req, res){
res.send('I am mail.example.com');
}));
app.use(vhost('*.mail.example.com', function(req, res){
res.send('I am *.example.com')
}));
app.listen(3000, function(){
console.log('Listening at port 3000');
});
Our /etc/hosts file contains this line, so that we can start the application in our localhost
127.0.0.1 mail.example.com
When we hit the url 'http://mail.example.com:3000', we do get the response 'I am mail.example.com'.
But when we hit the url 'http://a.mail.example.com:3000', we are getting the 'Server not found' response.
Am I doing anything wrong here?
OK we got this issue. It is nothing to do with vhost. The issue is with /etc/hosts. The line should be
127.0.0.1 *.mail.example.com
But wildcard is not supported in /etc/hosts file. Thus we need to allow the wildcard subdomains with DNS. Please refer http://askubuntu.com/questions/150135/how-to-block-specific-domains-in-hosts-file/150180#150180 for more info