Node.js is event driven, and when a request arrives, an event requestis created on http.Server. Thus, basically express.vhost(or indeed, connect.vhost) is an intermediate function that raises an event requestin another instance http.Server:
function vhost(req, res, next){
if (!req.headers.host) return next();
var host = req.headers.host.split(':')[0];
if (req.subdomains = regexp.exec(host)) {
req.subdomains = req.subdomains[0].split('.').slice(0, -1);
server.emit('request', req, res);
} else {
next();
}
};
source
share