Skip to content

Commit

Permalink
fix(groupRoutes): simplify .groupRoutes method
Browse files Browse the repository at this point in the history
  • Loading branch information
tunnckoCore committed Oct 16, 2016
1 parent a171a43 commit 04a88d7
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ app.listen(2222, () => {
})
```

### [.middleware](index.js#L479)
### [.middleware](index.js#L474)
> Active all routes that are defined. You can pass `opts` to pass different `prefix` for your routes. So you can have multiple prefixes with multiple routes using just one single router. You can also use multiple router instances. Pass `legacy: true` to `opts` and you will get generator function that can be used in Koa v1.
**Params**
Expand Down Expand Up @@ -367,7 +367,7 @@ app.listen(4321, () => {
})
```

### [.legacyMiddleware](index.js#L559)
### [.legacyMiddleware](index.js#L554)
> Converts the modern middleware routes to generator functions using [koa-convert][].back under the hood. It is sugar for the `.middleware(true)` or `.middleware({ legacy: true })`
* `returns` **{Function|GeneratorFunction}**
Expand Down
7 changes: 1 addition & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,12 +415,7 @@ KoaBetterRouter.prototype.groupRoutes = function groupRoutes (dest, src1, src2)
let pathname = dest.route + src1.route
let route = this.createRoute(dest.method, pathname, src1.middlewares)

if (utils.isObject(src2)) {
pathname = route.route + src2.route
route = this.createRoute(dest.method, pathname, src2.middlewares)
}

return route
return utils.isObject(src2) ? this.groupRoutes(route, src2) : route
}

/**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"test": "npm run coverage",
"posttest": "npm run lint:coverage",
"coverage": "nyc node test.js",
"lint:coverage": "nyc check-coverage --lines 100 --branches 95 --statements 100 --functions 100",
"lint:coverage": "nyc check-coverage --lines 100 --branches 97 --statements 100 --functions 100",
"report-coverage": "nyc report --reporter=text-lcov | coveralls",
"prerelease": "npm test",
"release": "standard-version --sign --no-verify",
Expand Down
2 changes: 1 addition & 1 deletion utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ utils.typeOf = function typeOf (val) {
}

utils.isObject = function isObject (val) {
return utils.typeOf(val) === 'object'
return val && utils.typeOf(val) === 'object'
}

utils.arrayify = function arrayify (val) {
Expand Down

0 comments on commit 04a88d7

Please sign in to comment.