find-my-way
Advanced tools
Comparing version 2.2.4 to 2.2.5
13
index.js
@@ -53,3 +53,3 @@ 'use strict' | ||
this.allowUnsafeRegex = opts.allowUnsafeRegex || false | ||
this.versioning = opts.versioning || acceptVersionStrategy | ||
this.versioning = opts.versioning || acceptVersionStrategy(false) | ||
this.tree = new Node({ versions: this.versioning.storage() }) | ||
@@ -109,2 +109,5 @@ this.routes = [] | ||
const version = opts.version | ||
if (version != null && this.versioning.disabled) { | ||
this.versioning = acceptVersionStrategy(true) | ||
} | ||
@@ -217,3 +220,4 @@ for (var i = 0, len = path.length; i < len; i++) { | ||
node = new Node( | ||
{ prefix: prefix.slice(len), | ||
{ | ||
prefix: prefix.slice(len), | ||
children: currentNode.children, | ||
@@ -223,3 +227,4 @@ kind: currentNode.kind, | ||
regex: currentNode.regex, | ||
versions: currentNode.versions } | ||
versions: currentNode.versions | ||
} | ||
) | ||
@@ -589,3 +594,3 @@ if (currentNode.wildcardChild !== null) { | ||
for (var i in http.METHODS) { | ||
if (!http.METHODS.hasOwnProperty(i)) continue | ||
if (!http.METHODS.hasOwnProperty(i)) continue // eslint-disable-line | ||
const m = http.METHODS[i] | ||
@@ -592,0 +597,0 @@ const methodName = m.toLowerCase() |
@@ -5,7 +5,18 @@ 'use strict' | ||
module.exports = { | ||
storage: SemVerStore, | ||
deriveVersion: function (req, ctx) { | ||
return req.headers['accept-version'] | ||
function build (enabled) { | ||
if (enabled) { | ||
return { | ||
storage: SemVerStore, | ||
deriveVersion: function (req, ctx) { | ||
return req.headers['accept-version'] | ||
} | ||
} | ||
} | ||
return { | ||
storage: SemVerStore, | ||
deriveVersion: function (req, ctx) {}, | ||
disabled: true | ||
} | ||
} | ||
module.exports = build |
{ | ||
"name": "find-my-way", | ||
"version": "2.2.4", | ||
"version": "2.2.5", | ||
"description": "Crazy fast http radix based router", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -147,4 +147,6 @@ # find-my-way | ||
If needed you can provide a `version` option, which will allow you to declare multiple versions of the same route. | ||
If needed you can provide a `version` option, which will allow you to declare multiple versions of the same route. If you never configure a versioned route, the `'Accept-Version'` header will be ignored. | ||
Remember to set a [Vary](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Vary) header in your responses with the value you are using for deifning the versioning (e.g.: 'Accept-Version'), to prevent cache poisoning attacks. You can also configure this as part your Proxy/CDN. | ||
###### default | ||
@@ -151,0 +153,0 @@ <a name="semver"></a> |
@@ -184,3 +184,3 @@ 'use strict' | ||
} catch (e) { | ||
t.is(e.message, `Method 'GET' already declared for route '/test'`) | ||
t.is(e.message, 'Method \'GET\' already declared for route \'/test\'') | ||
} | ||
@@ -202,3 +202,3 @@ }) | ||
} catch (e) { | ||
t.is(e.message, `Method 'GET' already declared for route '/test'`) | ||
t.is(e.message, 'Method \'GET\' already declared for route \'/test\'') | ||
} | ||
@@ -210,3 +210,3 @@ | ||
} catch (e) { | ||
t.is(e.message, `Method 'GET' already declared for route '/test/'`) | ||
t.is(e.message, 'Method \'GET\' already declared for route \'/test/\'') | ||
} | ||
@@ -225,3 +225,3 @@ }) | ||
} catch (e) { | ||
t.is(e.message, `Method 'GET' already declared for route '/test'`) | ||
t.is(e.message, 'Method \'GET\' already declared for route \'/test\'') | ||
} | ||
@@ -233,3 +233,3 @@ | ||
} catch (e) { | ||
t.is(e.message, `Method 'GET' already declared for route '/test/'`) | ||
t.is(e.message, 'Method \'GET\' already declared for route \'/test/\'') | ||
} | ||
@@ -251,3 +251,3 @@ }) | ||
} catch (e) { | ||
t.is(e.message, `Method 'GET' already declared for route '/test/hello'`) | ||
t.is(e.message, 'Method \'GET\' already declared for route \'/test/hello\'') | ||
} | ||
@@ -271,3 +271,3 @@ }) | ||
} catch (e) { | ||
t.is(e.message, `Method 'GET' already declared for route '/test/hello'`) | ||
t.is(e.message, 'Method \'GET\' already declared for route \'/test/hello\'') | ||
} | ||
@@ -279,3 +279,3 @@ | ||
} catch (e) { | ||
t.is(e.message, `Method 'GET' already declared for route '/test/hello/'`) | ||
t.is(e.message, 'Method \'GET\' already declared for route \'/test/hello/\'') | ||
} | ||
@@ -296,3 +296,3 @@ }) | ||
} catch (e) { | ||
t.is(e.message, `Method 'GET' already declared for route '/test/hello'`) | ||
t.is(e.message, 'Method \'GET\' already declared for route \'/test/hello\'') | ||
} | ||
@@ -304,5 +304,5 @@ | ||
} catch (e) { | ||
t.is(e.message, `Method 'GET' already declared for route '/test/hello/'`) | ||
t.is(e.message, 'Method \'GET\' already declared for route \'/test/hello/\'') | ||
} | ||
}) | ||
}) |
@@ -20,3 +20,3 @@ 'use strict' | ||
deriveVersion: (req, ctx) => { | ||
return req.headers['accept'] | ||
return req.headers.accept | ||
} | ||
@@ -23,0 +23,0 @@ } |
@@ -243,1 +243,26 @@ 'use strict' | ||
}) | ||
test('Versioning won\'t work if there are no versioned routes', t => { | ||
t.plan(2) | ||
const findMyWay = FindMyWay({ | ||
defaultRoute: (req, res) => { | ||
t.fail('We should not be here') | ||
} | ||
}) | ||
findMyWay.on('GET', '/', (req, res) => { | ||
t.pass('Yeah!') | ||
}) | ||
findMyWay.lookup({ | ||
method: 'GET', | ||
url: '/', | ||
headers: { 'accept-version': '2.x' } | ||
}, null) | ||
findMyWay.lookup({ | ||
method: 'GET', | ||
url: '/' | ||
}, null) | ||
}) |
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
172561
4808
396