find-my-way
Advanced tools
Comparing version 1.7.0 to 1.7.1
@@ -212,2 +212,3 @@ 'use strict' | ||
if (handle !== undefined) { | ||
var paramsObj = {} | ||
if (handle.paramsLength > 0) { | ||
@@ -217,3 +218,3 @@ var paramNames = handle.params | ||
for (i = 0; i < handle.paramsLength; i++) { | ||
handle.paramsObj[paramNames[i]] = params[i] | ||
paramsObj[paramNames[i]] = params[i] | ||
} | ||
@@ -224,3 +225,3 @@ } | ||
handler: handle.handler, | ||
params: handle.paramsObj, | ||
params: paramsObj, | ||
store: handle.store | ||
@@ -227,0 +228,0 @@ } |
@@ -59,7 +59,2 @@ 'use strict' | ||
var paramsObj = {} | ||
for (var i = 0; i < params.length; i++) { | ||
paramsObj[params[i]] = '' | ||
} | ||
this.map[method] = { | ||
@@ -69,4 +64,3 @@ handler: handler, | ||
store: store || null, | ||
paramsLength: params.length, | ||
paramsObj: paramsObj | ||
paramsLength: params.length | ||
} | ||
@@ -73,0 +67,0 @@ } |
{ | ||
"name": "find-my-way", | ||
"version": "1.7.0", | ||
"version": "1.7.1", | ||
"description": "Crazy fast http radix based router", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -119,4 +119,5 @@ # find-my-way | ||
``` | ||
This means that if you register two routes, the first static and the second dynamic with a shared part of the path, the static route will always take precedence. | ||
For example: | ||
##### Caveats | ||
* Since *static* routes have greater priority than *parametric* routes, when you register a static route and a dynamic route, which have part of their path equal, the static route shadows the parametric route, that becomes not accessible. For example: | ||
```js | ||
@@ -141,2 +142,14 @@ const assert = require('assert') | ||
* It's not possible to register two routes which differs only for their parameters, because internally they would be seen as the same route. In a such case you'll get an early error during the route registration phase. An example is worth thousand words: | ||
```js | ||
const findMyWay = FindMyWay({ | ||
defaultRoute: (req, res) => {} | ||
}) | ||
findMyWay.on('GET', '/user/:userId(^\\d+)', (req, res, params) => {}) | ||
findMyWay.on('GET', '/user/:username(^[a-z]+)', (req, res, params) => {}) | ||
// Method 'GET' already declared for route ':' | ||
``` | ||
<a name="shorthand-methods"></a> | ||
@@ -143,0 +156,0 @@ ##### Shorthand methods |
@@ -456,1 +456,23 @@ 'use strict' | ||
}) | ||
test('params does not keep the object reference', t => { | ||
t.plan(2) | ||
const findMyWay = FindMyWay() | ||
var first = true | ||
findMyWay.on('GET', '/test/:id', (req, res, params) => { | ||
if (first) { | ||
setTimeout(() => { | ||
t.is(params.id, 'hello') | ||
}, 10) | ||
} else { | ||
setTimeout(() => { | ||
t.is(params.id, 'world') | ||
}, 10) | ||
} | ||
first = false | ||
}) | ||
findMyWay.lookup({ method: 'GET', url: '/test/hello' }, null) | ||
findMyWay.lookup({ method: 'GET', url: '/test/world' }, 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
76172
2191
219