Comparing version 3.0.1 to 3.0.2
@@ -0,1 +1,7 @@ | ||
3.0.2 / 2015-10-12 | ||
================== | ||
* perf: hoist regular expressions | ||
* perf: use single regular expression for anchor checking | ||
3.0.1 / 2015-07-19 | ||
@@ -2,0 +8,0 @@ ================== |
46
index.js
/*! | ||
* vhost | ||
* Copyright(c) 2014 Jonathan Ong | ||
* Copyright(c) 2014 Douglas Christopher Wilson | ||
* Copyright(c) 2014-2015 Douglas Christopher Wilson | ||
* MIT Licensed | ||
@@ -11,2 +11,20 @@ */ | ||
/** | ||
* Module exports. | ||
* @public | ||
*/ | ||
module.exports = vhost | ||
/** | ||
* Module variables. | ||
* @private | ||
*/ | ||
var asteriskRegExp = /\*/g | ||
var asteriskReplace = '([^\.]+)' | ||
var endAnchoredRegExp = /(?:^|[^\\])(?:\\\\)*\$$/ | ||
var escapeRegExp = /([.+?^=!:${}()|\[\]\/\\])/g | ||
var escapeReplace = '\\$1' | ||
/** | ||
* Create a vhost middleware. | ||
@@ -20,3 +38,3 @@ * | ||
module.exports = function vhost(hostname, handle) { | ||
function vhost(hostname, handle) { | ||
if (!hostname) { | ||
@@ -37,3 +55,3 @@ throw new TypeError('argument hostname is required') | ||
return function vhost(req, res, next){ | ||
return function vhost(req, res, next) { | ||
var vhostdata = vhostof(req, regexp) | ||
@@ -50,4 +68,4 @@ | ||
handle(req, res, next) | ||
}; | ||
}; | ||
} | ||
} | ||
@@ -62,3 +80,3 @@ /** | ||
function hostnameof(req){ | ||
function hostnameof(req) { | ||
var host = req.headers.host | ||
@@ -88,3 +106,3 @@ | ||
function isregexp(val){ | ||
function isregexp(val) { | ||
return Object.prototype.toString.call(val) === '[object RegExp]' | ||
@@ -100,5 +118,5 @@ } | ||
function hostregexp(val){ | ||
function hostregexp(val) { | ||
var source = !isregexp(val) | ||
? String(val).replace(/([.+?^=!:${}()|\[\]\/\\])/g, '\\$1').replace(/\*/g, '([^\.]+)') | ||
? String(val).replace(escapeRegExp, escapeReplace).replace(asteriskRegExp, asteriskReplace) | ||
: val.source | ||
@@ -112,7 +130,5 @@ | ||
// force trailing anchor matching | ||
source = source.replace(/(\\*)(.)$/, function(s, b, c){ | ||
return c !== '$' || b.length % 2 === 1 | ||
? s + '$' | ||
: s | ||
}) | ||
if (!endAnchoredRegExp.test(source)) { | ||
source += '$' | ||
} | ||
@@ -131,3 +147,3 @@ return new RegExp(source, 'i') | ||
function vhostof(req, regexp){ | ||
function vhostof(req, regexp) { | ||
var host = req.headers.host | ||
@@ -134,0 +150,0 @@ var hostname = hostnameof(req) |
{ | ||
"name": "vhost", | ||
"description": "virtual domain hosting", | ||
"version": "3.0.1", | ||
"author": "Jonathan Ong <me@jongleberry.com> (http://jongleberry.com)", | ||
"version": "3.0.2", | ||
"contributors": [ | ||
"Douglas Christopher Wilson <doug@somethingdoug.com>" | ||
"Douglas Christopher Wilson <doug@somethingdoug.com>", | ||
"Jonathan Ong <me@jongleberry.com> (http://jongleberry.com)" | ||
], | ||
@@ -12,5 +12,5 @@ "license": "MIT", | ||
"devDependencies": { | ||
"istanbul": "0.3.17", | ||
"mocha": "2.2.5", | ||
"supertest": "1.0.1" | ||
"istanbul": "0.3.22", | ||
"mocha": "2.3.3", | ||
"supertest": "1.1.0" | ||
}, | ||
@@ -17,0 +17,0 @@ "files": [ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9795
129