Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Update vhost to use a table for all vhosts

  • Loading branch information...
commit d37790a6fcb856e7a7cdf24750f82416ba5b0652 1 parent ba516e5
Tim Caswell authored
Showing with 11 additions and 7 deletions.
  1. +11 −7 vhost.js
18 vhost.js
View
@@ -1,13 +1,17 @@
-module.exports = function setup(domain, handler) {
+module.exports = function setup(domainHandlers, defaultHandler) {
+ var domains = Object.keys(domainHandlers);
+ var length = domains.length;
return function handle(req, res, next) {
var host = req.headers.host;
- var i = host.indexOf(":");
- if (i >= 0) host = host.substr(0, i);
- if (host === domain) {
- handler(req, res, next);
- } else {
- next();
+ var p = host.indexOf(":");
+ if (p >= 0) host = host.substr(0, p);
+ for (var i = 0; i < length; i++) {
+ var domain = domains[i];
+ if (domain !== host) continue;
+ return domainHandlers[domain](req, res, next);
}
+ if (defaultHandler) return defaultHandler(req, res, next);
+ next();
};
};
Please sign in to comment.
Something went wrong with that request. Please try again.