find-my-way
Advanced tools
Comparing version 1.4.1 to 1.5.0
@@ -17,3 +17,3 @@ 'use strict' | ||
if (err) throw err | ||
console.log('Server listening on: http://localost:3000') | ||
console.log('Server listening on: http://localhost:3000') | ||
}) |
11
index.js
@@ -38,2 +38,9 @@ 'use strict' | ||
Router.prototype.on = function (method, path, handler, store) { | ||
if (Array.isArray(method)) { | ||
for (var k = 0; k < method.length; k++) { | ||
this.on(method[k], path, handler, store) | ||
} | ||
return | ||
} | ||
assert.equal(typeof method, 'string', 'Method should be a string') | ||
@@ -309,2 +316,6 @@ assert.equal(typeof path, 'string', 'Path should be a string') | ||
Router.prototype.all = function (path, handler, store) { | ||
this.on(httpMethods, path, handler, store) | ||
} | ||
module.exports = Router | ||
@@ -311,0 +322,0 @@ |
{ | ||
"name": "find-my-way", | ||
"version": "1.4.1", | ||
"version": "1.5.0", | ||
"description": "Crazy fast http radix based router", | ||
@@ -32,5 +32,5 @@ "main": "index.js", | ||
"request": "^2.81.0", | ||
"standard": "^10.0.2", | ||
"tap": "^10.3.2" | ||
"standard": "^10.0.3", | ||
"tap": "^10.7.2" | ||
} | ||
} |
@@ -80,2 +80,9 @@ # find-my-way | ||
You can also pass an array of methods if you need to declare multiple routes with the same handler but different method. | ||
```js | ||
router.on(['GET', 'POST'], '/', (req, res, params) => { | ||
// your code | ||
}) | ||
``` | ||
<a name="shorthand-methods"></a> | ||
@@ -96,2 +103,7 @@ ##### Shorthand methods | ||
If you need a route that supports *all* methods you can use the `all` api. | ||
```js | ||
router.all(path, handler [, store]) | ||
``` | ||
<a name="lookup"></a> | ||
@@ -98,0 +110,0 @@ #### lookup(request, response) |
@@ -19,2 +19,14 @@ 'use strict' | ||
test('Method should be a string (array)', t => { | ||
t.plan(1) | ||
const findMyWay = FindMyWay() | ||
try { | ||
findMyWay.on(['GET', 0], '/test', () => {}) | ||
t.fail('method shoukd be a string') | ||
} catch (e) { | ||
t.is(e.message, 'Method should be a string') | ||
} | ||
}) | ||
test('Path should be a string', t => { | ||
@@ -56,2 +68,14 @@ t.plan(1) | ||
test('Method is not an http method. (array)', t => { | ||
t.plan(1) | ||
const findMyWay = FindMyWay() | ||
try { | ||
findMyWay.on(['POST', 'GETT'], '/test', () => {}) | ||
t.fail('method is not a valid http method') | ||
} catch (e) { | ||
t.is(e.message, 'Method \'GETT\' is not an http method.') | ||
} | ||
}) | ||
test('The default route must be a function', t => { | ||
@@ -58,0 +82,0 @@ t.plan(1) |
@@ -28,2 +28,14 @@ 'use strict' | ||
test('register a route with multiple methods', t => { | ||
t.plan(2) | ||
const findMyWay = FindMyWay() | ||
findMyWay.on(['GET', 'POST'], '/test', () => { | ||
t.ok('inside the handler') | ||
}) | ||
findMyWay.lookup({ method: 'GET', url: '/test' }, null) | ||
findMyWay.lookup({ method: 'POST', url: '/test' }, null) | ||
}) | ||
test('default route', t => { | ||
@@ -30,0 +42,0 @@ t.plan(1) |
@@ -105,1 +105,20 @@ 'use strict' | ||
}) | ||
test('should support `.connect` shorthand', t => { | ||
t.plan(9) | ||
const findMyWay = FindMyWay() | ||
findMyWay.all('/test', () => { | ||
t.ok('inside the handler') | ||
}) | ||
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) | ||
}) |
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
46992
1333
153