find-my-way
Advanced tools
Comparing version 1.13.0 to 1.14.0
31
bench.js
@@ -15,40 +15,47 @@ 'use strict' | ||
findMyWay.on('GET', '/abc/def/ghi/lmn/opq/rst/uvz', () => true) | ||
findMyWay.on('GET', '/', { version: '1.2.0' }, () => true) | ||
suite | ||
.add('lookup static route', function () { | ||
findMyWay.lookup({ method: 'GET', url: '/' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/', headers: {} }, null) | ||
}) | ||
.add('lookup dynamic route', function () { | ||
findMyWay.lookup({ method: 'GET', url: '/user/tomas' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/user/tomas', headers: {} }, null) | ||
}) | ||
.add('lookup dynamic multi-parametric route', function () { | ||
findMyWay.lookup({ method: 'GET', url: '/customer/john-doe' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/customer/john-doe', headers: {} }, null) | ||
}) | ||
.add('lookup dynamic multi-parametric route with regex', function () { | ||
findMyWay.lookup({ method: 'GET', url: '/at/12h00m' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/at/12h00m', headers: {} }, null) | ||
}) | ||
.add('lookup long static route', function () { | ||
findMyWay.lookup({ method: 'GET', url: '/abc/def/ghi/lmn/opq/rst/uvz' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/abc/def/ghi/lmn/opq/rst/uvz', headers: {} }, null) | ||
}) | ||
.add('lookup long dynamic route', function () { | ||
findMyWay.lookup({ method: 'GET', url: '/user/qwertyuiopasdfghjklzxcvbnm/static' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/user/qwertyuiopasdfghjklzxcvbnm/static', headers: {} }, null) | ||
}) | ||
.add('lookup static versioned route', function () { | ||
findMyWay.lookup({ method: 'GET', url: '/', headers: { 'accept-version': '1.x' } }, null) | ||
}) | ||
.add('find static route', function () { | ||
findMyWay.find('GET', '/') | ||
findMyWay.find('GET', '/', undefined) | ||
}) | ||
.add('find dynamic route', function () { | ||
findMyWay.find('GET', '/user/tomas') | ||
findMyWay.find('GET', '/user/tomas', undefined) | ||
}) | ||
.add('find dynamic multi-parametric route', function () { | ||
findMyWay.find('GET', '/customer/john-doe') | ||
findMyWay.find('GET', '/customer/john-doe', undefined) | ||
}) | ||
.add('find dynamic multi-parametric route with regex', function () { | ||
findMyWay.find('GET', '/at/12h00m') | ||
findMyWay.find('GET', '/at/12h00m', undefined) | ||
}) | ||
.add('find long static route', function () { | ||
findMyWay.find('GET', '/abc/def/ghi/lmn/opq/rst/uvz') | ||
findMyWay.find('GET', '/abc/def/ghi/lmn/opq/rst/uvz', undefined) | ||
}) | ||
.add('find long dynamic route', function () { | ||
findMyWay.find('GET', '/user/qwertyuiopasdfghjklzxcvbnm/static') | ||
findMyWay.find('GET', '/user/qwertyuiopasdfghjklzxcvbnm/static', undefined) | ||
}) | ||
.add('find static versioned route', function () { | ||
findMyWay.find('GET', '/', '1.x') | ||
}) | ||
.on('cycle', function (event) { | ||
@@ -55,0 +62,0 @@ console.log(String(event.target)) |
89
index.js
@@ -42,3 +42,10 @@ 'use strict' | ||
Router.prototype.on = function on (method, path, handler, store) { | ||
Router.prototype.on = function on (method, path, opts, handler, store) { | ||
if (typeof opts === 'function') { | ||
if (handler !== undefined) { | ||
store = handler | ||
} | ||
handler = opts | ||
opts = {} | ||
} | ||
// path validation | ||
@@ -51,9 +58,9 @@ assert(typeof path === 'string', 'Path should be a string') | ||
this._on(method, path, handler, store) | ||
this._on(method, path, opts, handler, store) | ||
if (this.ignoreTrailingSlash && path !== '/' && !path.endsWith('*')) { | ||
if (path.endsWith('/')) { | ||
this._on(method, path.slice(0, -1), handler, store) | ||
this._on(method, path.slice(0, -1), opts, handler, store) | ||
} else { | ||
this._on(method, path + '/', handler, store) | ||
this._on(method, path + '/', opts, handler, store) | ||
} | ||
@@ -63,6 +70,6 @@ } | ||
Router.prototype._on = function _on (method, path, handler, store) { | ||
Router.prototype._on = function _on (method, path, opts, handler, store) { | ||
if (Array.isArray(method)) { | ||
for (var k = 0; k < method.length; k++) { | ||
this._on(method[k], path, handler, store) | ||
this._on(method[k], path, opts, handler, store) | ||
} | ||
@@ -82,2 +89,3 @@ return | ||
path: path, | ||
opts: opts, | ||
handler: handler, | ||
@@ -87,2 +95,4 @@ store: store | ||
const version = opts.version | ||
for (var i = 0, len = path.length; i < len; i++) { | ||
@@ -95,3 +105,3 @@ // search for parametric or wildcard routes | ||
// add the static part of the route to the tree | ||
this._insert(method, path.slice(0, i), 0, null, null, null, null) | ||
this._insert(method, path.slice(0, i), 0, null, null, null, null, version) | ||
@@ -134,6 +144,6 @@ // isolate the parameter name | ||
if (i === len) { | ||
return this._insert(method, path.slice(0, i), nodeType, params, handler, store, regex) | ||
return this._insert(method, path.slice(0, i), nodeType, params, handler, store, regex, version) | ||
} | ||
// add the parameter and continue with the search | ||
this._insert(method, path.slice(0, i), nodeType, params, null, null, regex) | ||
this._insert(method, path.slice(0, i), nodeType, params, null, null, regex, version) | ||
@@ -143,13 +153,13 @@ i-- | ||
} else if (path.charCodeAt(i) === 42) { | ||
this._insert(method, path.slice(0, i), 0, null, null, null, null) | ||
this._insert(method, path.slice(0, i), 0, null, null, null, null, version) | ||
// add the wildcard parameter | ||
params.push('*') | ||
return this._insert(method, path.slice(0, len), 2, params, handler, store, null) | ||
return this._insert(method, path.slice(0, len), 2, params, handler, store, null, version) | ||
} | ||
} | ||
// static route | ||
this._insert(method, path, 0, params, handler, store, null) | ||
this._insert(method, path, 0, params, handler, store, null, version) | ||
} | ||
Router.prototype._insert = function _insert (method, path, kind, params, handler, store, regex) { | ||
Router.prototype._insert = function _insert (method, path, kind, params, handler, store, regex, version) { | ||
const route = path | ||
@@ -182,3 +192,4 @@ var currentNode = this.tree | ||
new Node.Handlers(currentNode.handlers), | ||
currentNode.regex | ||
currentNode.regex, | ||
currentNode.versions | ||
) | ||
@@ -197,8 +208,17 @@ if (currentNode.wildcardChild !== null) { | ||
if (len === pathLen) { | ||
assert(!currentNode.getHandler(method), `Method '${method}' already declared for route '${route}'`) | ||
currentNode.setHandler(method, handler, params, store) | ||
if (version) { | ||
assert(!currentNode.getVersionHandler(version, method), `Method '${method}' already declared for route '${route}' version '${version}'`) | ||
currentNode.setVersionHandler(version, method, handler, params, store) | ||
} else { | ||
assert(!currentNode.getHandler(method), `Method '${method}' already declared for route '${route}'`) | ||
currentNode.setHandler(method, handler, params, store) | ||
} | ||
currentNode.kind = kind | ||
} else { | ||
node = new Node(path.slice(len), {}, kind, null, regex) | ||
node.setHandler(method, handler, params, store) | ||
node = new Node(path.slice(len), {}, kind, null, regex, null) | ||
if (version) { | ||
node.setVersionHandler(version, method, handler, params, store) | ||
} else { | ||
node.setHandler(method, handler, params, store) | ||
} | ||
currentNode.addChild(node) | ||
@@ -220,4 +240,9 @@ } | ||
// there are not children within the given label, let's create a new one! | ||
node = new Node(path, {}, kind, null, regex) | ||
node.setHandler(method, handler, params, store) | ||
node = new Node(path, {}, kind, null, regex, null) | ||
if (version) { | ||
node.setVersionHandler(version, method, handler, params, store) | ||
} else { | ||
node.setHandler(method, handler, params, store) | ||
} | ||
currentNode.addChild(node) | ||
@@ -227,4 +252,9 @@ | ||
} else if (handler) { | ||
assert(!currentNode.getHandler(method), `Method '${method}' already declared for route '${route}'`) | ||
currentNode.setHandler(method, handler, params, store) | ||
if (version) { | ||
assert(!currentNode.getVersionHandler(version, method), `Method '${method}' already declared for route '${route}' version '${version}'`) | ||
currentNode.setVersionHandler(version, method, handler, params, store) | ||
} else { | ||
assert(!currentNode.getHandler(method), `Method '${method}' already declared for route '${route}'`) | ||
currentNode.setHandler(method, handler, params, store) | ||
} | ||
} | ||
@@ -282,3 +312,3 @@ return | ||
newRoutes.forEach(function (route) { | ||
self.on(route.method, route.path, route.handler, route.store) | ||
self.on(route.method, route.path, route.opts, route.handler, route.store) | ||
}) | ||
@@ -288,3 +318,3 @@ } | ||
Router.prototype.lookup = function lookup (req, res) { | ||
var handle = this.find(req.method, sanitizeUrl(req.url)) | ||
var handle = this.find(req.method, sanitizeUrl(req.url), req.headers['accept-version']) | ||
if (handle === null) return this._defaultRoute(req, res) | ||
@@ -294,3 +324,3 @@ return handle.handler(req, res, handle.params, handle.store) | ||
Router.prototype.find = function find (method, path) { | ||
Router.prototype.find = function find (method, path, version) { | ||
var maxParamLength = this.maxParamLength | ||
@@ -315,3 +345,5 @@ var currentNode = this.tree | ||
if (pathLen === 0 || path === prefix) { | ||
var handle = currentNode.handlers[method] | ||
var handle = version === undefined | ||
? currentNode.handlers[method] | ||
: currentNode.getVersionHandler(version, method) | ||
if (handle !== null && handle !== undefined) { | ||
@@ -344,3 +376,6 @@ var paramsObj = {} | ||
var node = currentNode.findChild(path, method) | ||
var node = version === undefined | ||
? currentNode.findChild(path, method) | ||
: currentNode.findVersionChild(version, path, method) | ||
if (node === null) { | ||
@@ -347,0 +382,0 @@ node = currentNode.parametricBrother |
44
node.js
@@ -5,2 +5,3 @@ 'use strict' | ||
const http = require('http') | ||
const SemVerStore = require('semver-store') | ||
const Handlers = buildHandlers() | ||
@@ -17,3 +18,3 @@ | ||
function Node (prefix, children, kind, handlers, regex) { | ||
function Node (prefix, children, kind, handlers, regex, versions) { | ||
this.prefix = prefix || '/' | ||
@@ -28,2 +29,3 @@ this.label = this.prefix[0] | ||
this.parametricBrother = null | ||
this.versions = SemVerStore() | ||
} | ||
@@ -95,2 +97,3 @@ | ||
this.wildcardChild = null | ||
this.versions = SemVerStore() | ||
return this | ||
@@ -119,2 +122,18 @@ } | ||
Node.prototype.findVersionChild = function (version, path, method) { | ||
var child = this.children[path[0]] | ||
if (child !== undefined && (child.numberOfChildren > 0 || child.getVersionHandler(version, method) !== null)) { | ||
if (path.slice(0, child.prefix.length) === child.prefix) { | ||
return child | ||
} | ||
} | ||
child = this.children[':'] || this.children['*'] | ||
if (child !== undefined && (child.numberOfChildren > 0 || child.getVersionHandler(version, method) !== null)) { | ||
return child | ||
} | ||
return null | ||
} | ||
Node.prototype.setHandler = function (method, handler, params, store) { | ||
@@ -136,2 +155,20 @@ if (!handler) return | ||
Node.prototype.setVersionHandler = function (version, method, handler, params, store) { | ||
if (!handler) return | ||
const handlers = this.versions.get(version) || new Handlers() | ||
assert( | ||
handlers[method] === null, | ||
`There is already an handler with version '${version}' and method '${method}'` | ||
) | ||
handlers[method] = { | ||
handler: handler, | ||
params: params, | ||
store: store || null, | ||
paramsLength: params.length | ||
} | ||
this.versions.set(version, handlers) | ||
} | ||
Node.prototype.getHandler = function (method) { | ||
@@ -141,2 +178,7 @@ return this.handlers[method] | ||
Node.prototype.getVersionHandler = function (version, method) { | ||
var handlers = this.versions.get(version) | ||
return handlers === null ? handlers : handlers[method] | ||
} | ||
Node.prototype.prettyPrint = function (prefix, tail) { | ||
@@ -143,0 +185,0 @@ var paramName = '' |
{ | ||
"name": "find-my-way", | ||
"version": "1.13.0", | ||
"version": "1.14.0", | ||
"description": "Crazy fast http radix based router", | ||
@@ -30,12 +30,13 @@ "main": "index.js", | ||
"benchmark": "^2.1.4", | ||
"coveralls": "^3.0.0", | ||
"coveralls": "^3.0.1", | ||
"pre-commit": "^1.2.2", | ||
"request": "^2.83.0", | ||
"standard": "^10.0.3", | ||
"tap": "^11.0.0" | ||
"request": "^2.87.0", | ||
"standard": "^11.0.1", | ||
"tap": "^12.0.1" | ||
}, | ||
"dependencies": { | ||
"fast-decode-uri-component": "^1.0.0", | ||
"safe-regex": "^1.1.0" | ||
"safe-regex": "^1.1.0", | ||
"semver-store": "^0.2.0" | ||
} | ||
} |
@@ -79,3 +79,3 @@ # find-my-way | ||
<a name="on"></a> | ||
#### on(method, path, handler, [store]) | ||
#### on(method, path, [opts], handler, [store]) | ||
Register a new route. | ||
@@ -94,3 +94,22 @@ ```js | ||
##### on(methods[], path, handler, [store]) | ||
<a name="semver"></a> | ||
##### Versioned routes | ||
If needed you can provide a `version` option, which will allow you to declare multiple versions of the same route. The versioning should follow the [semver](https://semver.org/) specification.<br/> | ||
When using `lookup`, `find-my-way` will automatically detect the `Accept-Version` header and route the request accordingly.<br/> | ||
Internally `find-my-way` uses the [`semver-store`](https://github.com/delvedor/semver-store) to get the correct version of the route; *advanced ranges* and *pre-releases* currently are not supported.<br/> | ||
*Be aware that using this feature will cause a degradation of the overall performances of the router.* | ||
```js | ||
router.on('GET', '/example', { version: '1.2.0' }, (req, res, params) => { | ||
res.send('Hello from 1.2.0!') | ||
}) | ||
router.on('GET', '/example', { version: '2.4.0' }, (req, res, params) => { | ||
res.send('Hello from 2.4.0!') | ||
}) | ||
// The 'Accept-Version' header could be '1.2.0' as well as '2.x' or '2.4.x' | ||
``` | ||
If you declare multiple versions with the same *major* or *minor* `find-my-way` will always choose the highest compatible with the `Accept-Version` header value. | ||
##### on(methods[], path, [opts], handler, [store]) | ||
Register a new route for each method specified in the `methods` array. | ||
@@ -223,5 +242,6 @@ It comes handy when you need to declare multiple routes with the same handler but different methods. | ||
<a name="find"></a> | ||
#### find(method, path) | ||
#### find(method, path [, version]) | ||
Return (if present) the route registered in *method:path*.<br> | ||
The path must be sanitized, all the parameters and wildcards are decoded automatically. | ||
The path must be sanitized, all the parameters and wildcards are decoded automatically.<br/> | ||
You can also pass an optional version string, which should be conform to the [semver](https://semver.org/) specification. | ||
```js | ||
@@ -231,2 +251,6 @@ router.find('GET', '/example') | ||
// => null | ||
router.find('GET', '/example', '1.x') | ||
// => { handler: Function, params: Object, store: Object} | ||
// => null | ||
``` | ||
@@ -233,0 +257,0 @@ |
@@ -19,3 +19,3 @@ 'use strict' | ||
findMyWay.lookup({ method: 'GET', url: '/a/foo-bar/b' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/a/foo-bar/b', headers: {} }, null) | ||
}) | ||
@@ -35,3 +35,3 @@ | ||
findMyWay.lookup({ method: 'GET', url: '/a/foo-bar' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/a/foo-bar', headers: {} }, null) | ||
}) | ||
@@ -51,6 +51,6 @@ | ||
findMyWay.lookup({ method: 'GET', url: '/a/$mebar' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/a/foolol' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/a/foobaz' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/a/foolbar' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/a/$mebar', headers: {} }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/a/foolol', headers: {} }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/a/foobaz', headers: {} }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/a/foolbar', headers: {} }, null) | ||
}) | ||
@@ -70,3 +70,3 @@ | ||
findMyWay.lookup({ method: 'GET', url: '/a/foobar' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/a/foobar', headers: {} }, null) | ||
}) | ||
@@ -86,3 +86,3 @@ | ||
findMyWay.lookup({ method: 'GET', url: '/a/abc-deffoo' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/a/abc-deffoo', headers: {} }, null) | ||
}) | ||
@@ -103,3 +103,3 @@ | ||
findMyWay.lookup({ method: 'GET', url: '/a/foo-bar' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/a/foo-bar', headers: {} }, null) | ||
}) | ||
@@ -120,3 +120,3 @@ | ||
findMyWay.lookup({ method: 'GET', url: '/a/foo-bar-baz' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/a/foo-bar-baz', headers: {} }, null) | ||
}) | ||
@@ -137,3 +137,3 @@ | ||
findMyWay.lookup({ method: 'GET', url: '/a/foo-bar' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/a/foo-bar', headers: {} }, null) | ||
}) | ||
@@ -153,3 +153,3 @@ | ||
findMyWay.lookup({ method: 'GET', url: '/a/foo' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/a/foo', headers: {} }, null) | ||
}) | ||
@@ -170,3 +170,3 @@ | ||
findMyWay.lookup({ method: 'GET', url: '/at/0h42m' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/at/0h42m', headers: {} }, null) | ||
}) | ||
@@ -192,4 +192,4 @@ | ||
findMyWay.lookup({ method: 'GET', url: '/a/1111-2222-3333-4444-foo' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/a/1111-2222-3333-4445-bar/account' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/a/1111-2222-3333-4444-foo', headers: {} }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/a/1111-2222-3333-4445-bar/account', headers: {} }, null) | ||
}) | ||
@@ -210,3 +210,3 @@ | ||
findMyWay.lookup({ method: 'GET', url: '/a/foo-bar-baz' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/a/foo-bar-baz', headers: {} }, null) | ||
}) | ||
@@ -227,3 +227,3 @@ | ||
findMyWay.lookup({ method: 'GET', url: '/a/foo-barbaz-kuux' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/a/foo-barbaz-kuux', headers: {} }, null) | ||
}) | ||
@@ -244,3 +244,3 @@ | ||
findMyWay.lookup({ method: 'GET', url: '/a/foo-bar/baz' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/a/foo-bar/baz', headers: {} }, null) | ||
}) | ||
@@ -262,3 +262,3 @@ | ||
findMyWay.lookup({ method: 'GET', url: '/a/foo-bar/b/baz' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/a/foo-bar/b/baz', headers: {} }, null) | ||
}) | ||
@@ -280,3 +280,3 @@ | ||
findMyWay.lookup({ method: 'GET', url: '/a/foo-42/b/bar' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/a/foo-42/b/bar', headers: {} }, null) | ||
}) | ||
@@ -298,3 +298,3 @@ | ||
findMyWay.lookup({ method: 'GET', url: '/a/foo-42/b/bar' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/a/foo-42/b/bar', headers: {} }, null) | ||
}) |
@@ -19,3 +19,3 @@ 'use strict' | ||
findMyWay.lookup({ method: 'GET', url: '/a/perfectly-fine-route' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/a/perfectly-fine-route', headers: {} }, null) | ||
}) | ||
@@ -35,3 +35,3 @@ | ||
findMyWay.lookup({ method: 'GET', url: '/a' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/a', headers: {} }, null) | ||
}) | ||
@@ -51,3 +51,3 @@ | ||
findMyWay.lookup({ method: 'GET', url: '/a-non-existing-route' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/a-non-existing-route', headers: {} }, null) | ||
}) | ||
@@ -67,3 +67,3 @@ | ||
findMyWay.lookup({ method: 'GET', url: '/a//' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/a//', headers: {} }, null) | ||
}) | ||
@@ -83,3 +83,3 @@ | ||
findMyWay.lookup({ method: 'GET', url: '/a/' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/a/', headers: {} }, null) | ||
}) |
@@ -32,3 +32,3 @@ 'use strict' | ||
findMyWay.lookup( | ||
{ method: 'GET', url: '/test/hello' }, | ||
{ method: 'GET', url: '/test/hello', headers: {} }, | ||
null | ||
@@ -38,3 +38,3 @@ ) | ||
findMyWay.lookup( | ||
{ method: 'GET', url: '/test/hello/world' }, | ||
{ method: 'GET', url: '/test/hello/world', headers: {} }, | ||
null | ||
@@ -44,3 +44,3 @@ ) | ||
findMyWay.lookup( | ||
{ method: 'GET', url: '/test/' }, | ||
{ method: 'GET', url: '/test/', headers: {} }, | ||
null | ||
@@ -67,3 +67,3 @@ ) | ||
findMyWay.lookup( | ||
{ method: 'GET', url: '/test/hello' }, | ||
{ method: 'GET', url: '/test/hello', headers: {} }, | ||
null | ||
@@ -73,3 +73,3 @@ ) | ||
findMyWay.lookup( | ||
{ method: 'OPTIONS', url: '/test/hello' }, | ||
{ method: 'OPTIONS', url: '/test/hello', headers: {} }, | ||
null | ||
@@ -100,3 +100,3 @@ ) | ||
findMyWay.lookup( | ||
{ method: 'GET', url: '/test/hello' }, | ||
{ method: 'GET', url: '/test/hello', headers: {} }, | ||
null | ||
@@ -106,3 +106,3 @@ ) | ||
findMyWay.lookup( | ||
{ method: 'GET', url: '/test/helloo' }, | ||
{ method: 'GET', url: '/test/helloo', headers: {} }, | ||
null | ||
@@ -112,3 +112,3 @@ ) | ||
findMyWay.lookup( | ||
{ method: 'OPTIONS', url: '/test/' }, | ||
{ method: 'OPTIONS', url: '/test/', headers: {} }, | ||
null | ||
@@ -118,3 +118,3 @@ ) | ||
findMyWay.lookup( | ||
{ method: 'OPTIONS', url: '/test' }, | ||
{ method: 'OPTIONS', url: '/test', headers: {} }, | ||
null | ||
@@ -124,3 +124,3 @@ ) | ||
findMyWay.lookup( | ||
{ method: 'OPTIONS', url: '/test/helloo' }, | ||
{ method: 'OPTIONS', url: '/test/helloo', headers: {} }, | ||
null | ||
@@ -151,3 +151,3 @@ ) | ||
findMyWay.lookup( | ||
{ method: 'OPTIONS', url: '/test1/foo' }, | ||
{ method: 'OPTIONS', url: '/test1/foo', headers: {} }, | ||
null | ||
@@ -178,3 +178,3 @@ ) | ||
findMyWay.lookup( | ||
{ method: 'OPTIONS', url: '/test1/foo' }, | ||
{ method: 'OPTIONS', url: '/test1/foo', headers: {} }, | ||
null | ||
@@ -184,3 +184,3 @@ ) | ||
findMyWay.lookup( | ||
{ method: 'OPTIONS', url: '/test/foo' }, | ||
{ method: 'OPTIONS', url: '/test/foo', headers: {} }, | ||
null | ||
@@ -215,3 +215,3 @@ ) | ||
findMyWay.lookup( | ||
{ method: 'OPTIONS', url: '/test1/foo' }, | ||
{ method: 'OPTIONS', url: '/test1/foo', headers: {} }, | ||
null | ||
@@ -221,3 +221,3 @@ ) | ||
findMyWay.lookup( | ||
{ method: 'OPTIONS', url: '/test/foo/hey' }, | ||
{ method: 'OPTIONS', url: '/test/foo/hey', headers: {} }, | ||
null | ||
@@ -227,3 +227,3 @@ ) | ||
findMyWay.lookup( | ||
{ method: 'GET', url: '/example/foo' }, | ||
{ method: 'GET', url: '/example/foo', headers: {} }, | ||
null | ||
@@ -258,3 +258,3 @@ ) | ||
findMyWay.lookup( | ||
{ method: 'GET', url: '/foo1/bar1/kuux' }, | ||
{ method: 'GET', url: '/foo1/bar1/kuux', headers: {} }, | ||
null | ||
@@ -285,3 +285,3 @@ ) | ||
findMyWay.lookup( | ||
{ method: 'GET', url: '/foo1/bar1/kuux' }, | ||
{ method: 'GET', url: '/foo1/bar1/kuux', headers: {} }, | ||
null | ||
@@ -312,3 +312,3 @@ ) | ||
findMyWay.lookup( | ||
{ method: 'GET', url: '/foo1/bar1/kuux' }, | ||
{ method: 'GET', url: '/foo1/bar1/kuux', headers: {} }, | ||
null | ||
@@ -347,3 +347,3 @@ ) | ||
findMyWay.lookup( | ||
{ method: 'GET', url: '/foo1/bar1/kuux' }, | ||
{ method: 'GET', url: '/foo1/bar1/kuux', headers: {} }, | ||
null | ||
@@ -382,3 +382,3 @@ ) | ||
findMyWay.lookup( | ||
{ method: 'GET', url: '/foo3/bar1' }, | ||
{ method: 'GET', url: '/foo3/bar1', headers: {} }, | ||
null | ||
@@ -417,3 +417,3 @@ ) | ||
findMyWay.lookup( | ||
{ method: 'GET', url: '/foo4/param' }, | ||
{ method: 'GET', url: '/foo4/param', headers: {} }, | ||
null | ||
@@ -452,3 +452,3 @@ ) | ||
findMyWay.lookup( | ||
{ method: 'GET', url: '/foo1/param' }, | ||
{ method: 'GET', url: '/foo1/param', headers: {} }, | ||
null | ||
@@ -487,3 +487,3 @@ ) | ||
findMyWay.lookup( | ||
{ method: 'GET', url: '/foo1/param/hello/test/long/routee' }, | ||
{ method: 'GET', url: '/foo1/param/hello/test/long/routee', headers: {} }, | ||
null | ||
@@ -522,3 +522,3 @@ ) | ||
findMyWay.lookup( | ||
{ method: 'GET', url: '/foo4/param/hello/test/long/routee' }, | ||
{ method: 'GET', url: '/foo4/param/hello/test/long/routee', headers: {} }, | ||
null | ||
@@ -561,3 +561,3 @@ ) | ||
findMyWay.lookup( | ||
{ method: 'GET', url: '/foo3/hello' }, | ||
{ method: 'GET', url: '/foo3/hello', headers: {} }, | ||
null | ||
@@ -600,5 +600,5 @@ ) | ||
findMyWay.lookup( | ||
{ method: 'GET', url: '/foo3/hello/world' }, | ||
{ method: 'GET', url: '/foo3/hello/world', headers: {} }, | ||
null | ||
) | ||
}) |
@@ -23,3 +23,3 @@ 'use strict' | ||
findMyWay.lookup({ method: 'GET', url: '/winter' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/winter', headers: {} }, null) | ||
}) | ||
@@ -43,3 +43,3 @@ | ||
findMyWay.lookup({ method: 'GET', url: '/woo' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/woo', headers: {} }, null) | ||
}) | ||
@@ -63,3 +63,3 @@ | ||
findMyWay.lookup({ method: 'GET', url: '/winter/coming' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/winter/coming', headers: {} }, null) | ||
}) | ||
@@ -83,3 +83,3 @@ | ||
findMyWay.lookup({ method: 'GET', url: '/example/shared/nested/other' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/example/shared/nested/other', headers: {} }, null) | ||
}) | ||
@@ -107,3 +107,3 @@ | ||
findMyWay.lookup({ method: 'GET', url: '/winter' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/winter', headers: {} }, null) | ||
}) | ||
@@ -131,3 +131,3 @@ | ||
findMyWay.lookup({ method: 'GET', url: '/winter/coming' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/winter/coming', headers: {} }, null) | ||
}) | ||
@@ -155,3 +155,3 @@ | ||
findMyWay.lookup({ method: 'GET', url: '/winter' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/winter', headers: {} }, null) | ||
}) |
@@ -50,3 +50,3 @@ 'use strict' | ||
findMyWay.lookup({ url: '/text', method: 'GET' }) | ||
findMyWay.lookup({ url: '/text', method: 'GET', headers: {} }) | ||
}) |
@@ -55,3 +55,3 @@ 'use strict' | ||
findMyWay.lookup({ method: 'GET', url: '/test' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/test', headers: {} }, null) | ||
}) | ||
@@ -67,4 +67,4 @@ | ||
findMyWay.lookup({ method: 'GET', url: '/test' }, null) | ||
findMyWay.lookup({ method: 'POST', url: '/test' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/test', headers: {} }, null) | ||
findMyWay.lookup({ method: 'POST', url: '/test', headers: {} }, null) | ||
}) | ||
@@ -141,3 +141,3 @@ | ||
findMyWay.lookup( | ||
{ method: 'GET', url: '/foo2/first/second' }, | ||
{ method: 'GET', url: '/foo2/first/second', headers: {} }, | ||
null | ||
@@ -240,3 +240,3 @@ ) | ||
findMyWay.lookup({ method: 'GET', url: '/test' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/test', headers: {} }, null) | ||
}) | ||
@@ -252,3 +252,3 @@ | ||
findMyWay.lookup({ method: 'GET', url: '/test/hello' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/test/hello', headers: {} }, null) | ||
}) | ||
@@ -268,4 +268,4 @@ | ||
findMyWay.lookup({ method: 'GET', url: '/test/hello' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/other-test/world' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/test/hello', headers: {} }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/other-test/world', headers: {} }, null) | ||
}) | ||
@@ -285,4 +285,4 @@ | ||
findMyWay.lookup({ method: 'GET', url: '/test/hello' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/test/world/world' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/test/hello', headers: {} }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/test/world/world', headers: {} }, null) | ||
}) | ||
@@ -299,3 +299,3 @@ | ||
findMyWay.lookup({ method: 'GET', url: '/test/hello/test/world' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/test/hello/test/world', headers: {} }, null) | ||
}) | ||
@@ -316,4 +316,4 @@ | ||
findMyWay.lookup({ method: 'GET', url: '/test' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/test/hello/test/world' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/test', headers: {} }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/test/hello/test/world', headers: {} }, null) | ||
}) | ||
@@ -329,3 +329,3 @@ | ||
findMyWay.lookup({ method: 'GET', url: '/abc/def/ghi/lmn/opq/rst/uvz' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/abc/def/ghi/lmn/opq/rst/uvz', headers: {} }, null) | ||
}) | ||
@@ -343,3 +343,3 @@ | ||
findMyWay.lookup({ method: 'GET', url: '/abc/def/ghi/lmn/opq/rst/uvz' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/abc/def/ghi/lmn/opq/rst/uvz', headers: {} }, null) | ||
}) | ||
@@ -380,6 +380,6 @@ | ||
findMyWay.lookup({ method: 'GET', url: '/abc/def' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/abc/def/ghi/lmn' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/abc/def/ghi/lmn/opq/rst' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/abc/def/ghi/lmn/opq/rst/uvz' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/abc/def', headers: {} }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/abc/def/ghi/lmn', headers: {} }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/abc/def/ghi/lmn/opq/rst', headers: {} }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/abc/def/ghi/lmn/opq/rst/uvz', headers: {} }, null) | ||
}) | ||
@@ -407,6 +407,6 @@ | ||
findMyWay.lookup({ method: 'GET', url: '/f' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/ff' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/ffa' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/ffb' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/f', headers: {} }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/ff', headers: {} }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/ffa', headers: {} }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/ffb', headers: {} }, null) | ||
}) | ||
@@ -423,3 +423,3 @@ | ||
findMyWay.lookup( | ||
{ method: 'GET', url: '/test/hello' }, | ||
{ method: 'GET', url: '/test/hello', headers: {} }, | ||
null | ||
@@ -438,3 +438,3 @@ ) | ||
findMyWay.lookup( | ||
{ method: 'GET', url: '/test/hello' }, | ||
{ method: 'GET', url: '/test/hello', headers: {} }, | ||
null | ||
@@ -557,3 +557,3 @@ ) | ||
findMyWay.lookup({ method: 'GET', url: '/test/hello' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/test/hello', headers: {} }, null) | ||
}) | ||
@@ -573,3 +573,3 @@ | ||
findMyWay.lookup({ method: 'GET', url: '/test/hello' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/test/hello', headers: {} }, null) | ||
}) | ||
@@ -597,4 +597,4 @@ | ||
findMyWay.lookup({ method: 'GET', url: '/test' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/test/hello' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/test', headers: {} }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/test/hello', headers: {} }, null) | ||
}) | ||
@@ -622,4 +622,4 @@ | ||
findMyWay.lookup({ method: 'GET', url: '/test/id' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/id' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/test/id', headers: {} }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/id', headers: {} }, null) | ||
}) | ||
@@ -644,4 +644,4 @@ | ||
findMyWay.lookup({ method: 'GET', url: '/example/shared/nested/oopss' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/example/other/nested/oops' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/example/shared/nested/oopss', headers: {} }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/example/other/nested/oops', headers: {} }, null) | ||
}) | ||
@@ -661,4 +661,4 @@ | ||
findMyWay.lookup({ method: 'GET', url: '/test/hello' }, null) | ||
findMyWay.lookup({ method: 'POST', url: '/test/world' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/test/hello', headers: {} }, null) | ||
findMyWay.lookup({ method: 'POST', url: '/test/world', headers: {} }, null) | ||
}) | ||
@@ -684,4 +684,4 @@ | ||
findMyWay.lookup({ method: 'GET', url: '/test/hello' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/test/world' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/test/hello', headers: {} }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/test/world', headers: {} }, null) | ||
}) | ||
@@ -701,3 +701,3 @@ | ||
findMyWay.lookup({ method: 'TROLL', url: '/' }, null) | ||
findMyWay.lookup({ method: 'TROLL', url: '/', headers: {} }, null) | ||
}) | ||
@@ -717,3 +717,3 @@ | ||
findMyWay.lookup({ method: 'TROLL', url: '/hello/world' }, null) | ||
findMyWay.lookup({ method: 'TROLL', url: '/hello/world', headers: {} }, null) | ||
}) | ||
@@ -720,0 +720,0 @@ |
@@ -15,3 +15,3 @@ 'use strict' | ||
findMyWay.lookup({ method: 'GET', url: '/test?hello=world' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/test?hello=world', headers: {} }, null) | ||
}) | ||
@@ -27,3 +27,3 @@ | ||
findMyWay.lookup({ method: 'GET', url: '/test#hello' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/test#hello', headers: {} }, null) | ||
}) | ||
@@ -39,3 +39,3 @@ | ||
findMyWay.lookup({ method: 'GET', url: '/test;jsessionid=123456' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/test;jsessionid=123456', headers: {} }, null) | ||
}) |
@@ -19,3 +19,3 @@ 'use strict' | ||
findMyWay.lookup({ method: 'GET', url: '/test/12' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/test/12', headers: {} }, null) | ||
}) | ||
@@ -35,3 +35,3 @@ | ||
findMyWay.lookup({ method: 'GET', url: '/test/test' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/test/test', headers: {} }, null) | ||
}) | ||
@@ -51,3 +51,3 @@ | ||
findMyWay.lookup({ method: 'GET', url: '/test/12/hello' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/test/12/hello', headers: {} }, null) | ||
}) | ||
@@ -68,3 +68,3 @@ | ||
findMyWay.lookup({ method: 'GET', url: '/test/12/hello/world' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/test/12/hello/world', headers: {} }, null) | ||
}) | ||
@@ -85,3 +85,3 @@ | ||
findMyWay.lookup({ method: 'GET', url: '/test/12/hello/15' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/test/12/hello/15', headers: {} }, null) | ||
}) | ||
@@ -101,3 +101,3 @@ | ||
findMyWay.lookup({ method: 'GET', url: '/test/12/hello/test' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/test/12/hello/test', headers: {} }, null) | ||
}) | ||
@@ -117,3 +117,3 @@ | ||
findMyWay.lookup({ method: 'GET', url: '/test/12.png' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/test/12.png', headers: {} }, null) | ||
}) | ||
@@ -133,3 +133,3 @@ | ||
findMyWay.lookup({ method: 'GET', url: '/test/aa.png' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/test/aa.png', headers: {} }, null) | ||
}) | ||
@@ -136,0 +136,0 @@ |
@@ -267,1 +267,38 @@ 'use strict' | ||
}) | ||
test('versioned routes', t => { | ||
t.plan(5) | ||
const findMyWay = FindMyWay() | ||
findMyWay.on('GET', '/test', { version: '1.2.3' }, (req, res, params) => { | ||
res.end('ok') | ||
}) | ||
const server = http.createServer((req, res) => { | ||
findMyWay.lookup(req, res) | ||
}) | ||
server.listen(0, err => { | ||
t.error(err) | ||
server.unref() | ||
request({ | ||
method: 'GET', | ||
uri: 'http://localhost:' + server.address().port + '/test', | ||
headers: { 'Accept-Version': '1.x' } | ||
}, (err, response, body) => { | ||
t.error(err) | ||
t.strictEqual(response.statusCode, 200) | ||
}) | ||
request({ | ||
method: 'GET', | ||
uri: 'http://localhost:' + server.address().port + '/test', | ||
headers: { 'Accept-Version': '2.x' } | ||
}, (err, response, body) => { | ||
t.error(err) | ||
t.strictEqual(response.statusCode, 404) | ||
}) | ||
}) | ||
}) |
@@ -23,3 +23,3 @@ 'use strict' | ||
findMyWay.lookup({ method: m, url: '/test' }, null) | ||
findMyWay.lookup({ method: m, url: '/test', headers: {} }, null) | ||
}) | ||
@@ -37,13 +37,13 @@ } | ||
findMyWay.lookup({ method: 'GET', url: '/test' }, null) | ||
findMyWay.lookup({ method: 'DELETE', url: '/test' }, null) | ||
findMyWay.lookup({ method: 'HEAD', url: '/test' }, null) | ||
findMyWay.lookup({ method: 'PATCH', url: '/test' }, null) | ||
findMyWay.lookup({ method: 'POST', url: '/test' }, null) | ||
findMyWay.lookup({ method: 'PUT', url: '/test' }, null) | ||
findMyWay.lookup({ method: 'OPTIONS', url: '/test' }, null) | ||
findMyWay.lookup({ method: 'TRACE', url: '/test' }, null) | ||
findMyWay.lookup({ method: 'CONNECT', url: '/test' }, null) | ||
findMyWay.lookup({ method: 'COPY', url: '/test' }, null) | ||
findMyWay.lookup({ method: 'SUBSCRIBE', url: '/test' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/test', headers: {} }, null) | ||
findMyWay.lookup({ method: 'DELETE', url: '/test', headers: {} }, null) | ||
findMyWay.lookup({ method: 'HEAD', url: '/test', headers: {} }, null) | ||
findMyWay.lookup({ method: 'PATCH', url: '/test', headers: {} }, null) | ||
findMyWay.lookup({ method: 'POST', url: '/test', headers: {} }, null) | ||
findMyWay.lookup({ method: 'PUT', url: '/test', headers: {} }, null) | ||
findMyWay.lookup({ method: 'OPTIONS', url: '/test', headers: {} }, null) | ||
findMyWay.lookup({ method: 'TRACE', url: '/test', headers: {} }, null) | ||
findMyWay.lookup({ method: 'CONNECT', url: '/test', headers: {} }, null) | ||
findMyWay.lookup({ method: 'COPY', url: '/test', headers: {} }, null) | ||
findMyWay.lookup({ method: 'SUBSCRIBE', url: '/test', headers: {} }, null) | ||
}) |
@@ -15,3 +15,3 @@ 'use strict' | ||
findMyWay.lookup({ method: 'GET', url: '/test' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/test', headers: {} }, null) | ||
}) | ||
@@ -43,3 +43,3 @@ | ||
bool = true | ||
findMyWay.lookup({ method: 'GET', url: '/test' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/test', headers: {} }, null) | ||
} else { | ||
@@ -50,3 +50,3 @@ t.is(store.hello, 'hello') | ||
findMyWay.lookup({ method: 'GET', url: '/test' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/test', headers: {} }, 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
126246
28
3596
281
4
3
+ Addedsemver-store@^0.2.0
+ Addedsemver-store@0.2.2(transitive)