Skip to content

Commit

Permalink
Fixed vhost() middleware. Closes #494
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Feb 29, 2012
1 parent be38c62 commit 8b7796f
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/middleware/vhost.js
@@ -1,3 +1,4 @@

/*!
* Connect - vhost
* Copyright(c) 2010 Sencha Inc.
Expand All @@ -15,6 +16,9 @@
* .use(connect.vhost('bar.com', barApp))
* .use(connect.vhost('*.com', mainApp))
*
* The `server` may be a Connect server or
* a regular Node `http.Server`.
*
* @param {String} hostname
* @param {Server} server
* @return {Function}
Expand All @@ -29,11 +33,8 @@ module.exports = function vhost(hostname, server){
return 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();
}
if (!regexp.test(host)) return next();
if ('function' == typeof server) return server(req, res, next);
server.emit('request', req, res);
};
};

0 comments on commit 8b7796f

Please sign in to comment.