koa-trie-router
Advanced tools
Comparing version 1.0.6 to 1.0.7
@@ -10,9 +10,7 @@ var Router = require('./router') | ||
// If no match, go to next middleware | ||
if (!node) | ||
return yield* next | ||
if (!node) return yield* next | ||
// If no HEAD middleware, default to GET. | ||
var method = this.method | ||
if (method === 'HEAD' && !node.HEAD) | ||
method = 'GET' | ||
if (method === 'HEAD' && !node.HEAD) method = 'GET' | ||
@@ -40,2 +38,2 @@ // OPTIONS support | ||
function* noop() {} | ||
function* noop() {} |
@@ -19,6 +19,5 @@ var routington = require('routington') | ||
return function () { | ||
if (!methods[this.method]) | ||
this.throw(501, this.method + ' is not implemented') | ||
if (!methods[this.method]) this.throw(501, this.method + ' is not implemented') | ||
return this | ||
} | ||
} |
@@ -0,2 +1,4 @@ | ||
var compose = require('koa-compose') | ||
var flatten = require('flatten') | ||
var METHODS = require('methods').map(function (method) { | ||
@@ -7,3 +9,2 @@ return method.toUpperCase() | ||
var Router = require('./router') | ||
var utils = require('./utils') | ||
@@ -35,10 +36,8 @@ Router.prototype.routes = function () { | ||
if (!Array.isArray(paths)) | ||
paths = [paths] | ||
paths = utils.flatten(paths).filter(Boolean) | ||
if (!Array.isArray(paths)) paths = [paths] | ||
paths = flatten(paths).filter(Boolean) | ||
var nodes = this.nodes = [] | ||
if (!paths.length) | ||
throw new Error('Route must have a path') | ||
if (!paths.length) throw new Error('Route must have a path') | ||
@@ -48,3 +47,2 @@ paths.forEach(function (path) { | ||
throw new TypeError('Paths must be strings: ' + path) | ||
if (path !== '/' && path[0] !== '/') | ||
@@ -54,9 +52,7 @@ throw new Error('Paths must start with a "/": ' + path) | ||
router.trie.define(path).forEach(function (node) { | ||
if (!~nodes.indexOf(node)) | ||
nodes.push(node) | ||
if (!~nodes.indexOf(node)) nodes.push(node) | ||
}) | ||
}) | ||
if (!nodes.length) | ||
throw new Error('No routes defined. Something went wrong.') | ||
if (!nodes.length) throw new Error('No routes defined. Something went wrong.') | ||
} | ||
@@ -70,9 +66,7 @@ | ||
implementedMethods[method] = true | ||
if (method === 'GET') | ||
implementedMethods.HEAD = true | ||
if (method === 'GET') implementedMethods.HEAD = true | ||
// Take out all the falsey middleware | ||
var stack = utils.flatten(generators).filter(Boolean) | ||
if (!stack.length) | ||
return | ||
var stack = flatten(generators).filter(Boolean) | ||
if (!stack.length) return | ||
@@ -108,3 +102,3 @@ this.nodes.forEach(function (node) { | ||
Route.prototype[method.toLowerCase()] = function () { | ||
this._append(method, utils.flatten([].slice.call(arguments))) | ||
this._append(method, flatten([].slice.call(arguments))) | ||
return this | ||
@@ -114,2 +108,2 @@ } | ||
Route.prototype.del = Route.prototype.delete | ||
Route.prototype.del = Route.prototype.delete |
{ | ||
"name": "koa-trie-router", | ||
"description": "Trie-routing for Koa", | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"author": { | ||
@@ -14,15 +14,29 @@ "name": "Jonathan Ong", | ||
"dependencies": { | ||
"routington": "0", | ||
"methods": "1", | ||
"flatten": "0", | ||
"routington": "1", | ||
"koa-compose": "2" | ||
}, | ||
"devDependencies": { | ||
"koa": "*", | ||
"mocha": "*", | ||
"should": "*", | ||
"supertest": "*" | ||
"koa": "0", | ||
"mocha": "1", | ||
"should": "3", | ||
"supertest": "0", | ||
"istanbul-harmony": "0" | ||
}, | ||
"scripts": { | ||
"test": "mocha --require should --reporter spec --harmony-generators" | ||
} | ||
"test": "mocha --harmony-generators --reporter spec --require should", | ||
"test-cov": "node --harmony-generators node_modules/.bin/istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --require should", | ||
"test-travis": "node --harmony-generators node_modules/.bin/istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter dot --require should" | ||
}, | ||
"files": [ | ||
"lib" | ||
], | ||
"main": "lib", | ||
"keywords": [ | ||
"koa", | ||
"koajs", | ||
"router", | ||
"trie" | ||
] | ||
} |
@@ -1,3 +0,8 @@ | ||
# Koa Trie Router [![Build Status](https://travis-ci.org/koajs/trie-router.png)](https://travis-ci.org/koajs/trie-router) | ||
# Koa Trie Router | ||
[![NPM version][npm-image]][npm-url] | ||
[![build status][travis-image]][travis-url] | ||
[![Test coverage][coveralls-image]][coveralls-url] | ||
[![Gittip][gittip-image]][gittip-url] | ||
[Trie](http://en.wikipedia.org/wiki/Trie) routing for Koa based on [routington](https://github.com/jonathanong/routington). | ||
@@ -111,1 +116,10 @@ | ||
In `trie-router`, routes are orthogonal and strict. Unlike regexp routing, there's no wildcard routing and you can't `next` to the next matching route. | ||
[npm-image]: https://img.shields.io/npm/v/koa-trie-router.svg?style=flat | ||
[npm-url]: https://npmjs.org/package/koa-trie-router | ||
[travis-image]: https://img.shields.io/travis/koajs/trie-router.svg?style=flat | ||
[travis-url]: https://travis-ci.org/koajs/trie-router | ||
[coveralls-image]: https://img.shields.io/coveralls/koajs/trie-router.svg?style=flat | ||
[coveralls-url]: https://coveralls.io/r/koajs/trie-router?branch=master | ||
[gittip-image]: https://img.shields.io/gittip/jonathanong.svg?style=flat | ||
[gittip-url]: https://www.gittip.com/jonathanong/ |
125
8599
4
5
6
142
+ Addedflatten@0
+ Addeddeep-equal@1.0.1(transitive)
+ Addeddepd@1.1.2(transitive)
+ Addedflatten@0.0.1(transitive)
+ Addedhttp-assert@1.5.0(transitive)
+ Addedhttp-errors@1.8.1(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedroutington@1.0.3(transitive)
+ Addedsetprototypeof@1.2.0(transitive)
+ Addedstatuses@1.5.0(transitive)
+ Addedtoidentifier@1.0.1(transitive)
- Removedroutington@0.1.3(transitive)
Updatedroutington@1