Skip to content

Commit b450b9f

Browse files
committed
minor source code refactoring
1 parent 7e63dfd commit b450b9f

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

index.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
const op = updateParams => (req, res, params) => {
2-
if (updateParams) {
3-
req.params = params
4-
}
1+
const handlers = {
2+
match: updateParams => (req, res, params) => {
3+
if (updateParams) {
4+
req.params = params
5+
}
56

6-
return true
7+
return true
8+
},
9+
default: () => false
710
}
811

9-
module.exports = function (routerOpts = {}, routerFactory) {
10-
routerOpts.defaultRoute = () => false
11-
routerFactory = routerFactory || require('find-my-way')
12+
module.exports = function (routerOpts = {}, routerFactory = require('find-my-way')) {
13+
routerOpts.defaultRoute = handlers.default
1214

1315
function exec (options, isIff = true) {
1416
const middleware = this
@@ -20,12 +22,12 @@ module.exports = function (routerOpts = {}, routerFactory) {
2022
if (opts.endpoints && opts.endpoints.length) {
2123
// setup matching router
2224
opts.endpoints
23-
.map(endpoint => typeof endpoint === 'string' ? { methods: ['GET'], url: endpoint } : endpoint)
24-
.forEach(({ methods, url, version, updateParams = false }) => {
25+
.map(endpoint => typeof endpoint === 'string' ? { url: endpoint } : endpoint)
26+
.forEach(({ methods = ['GET'], url, version, updateParams = false }) => {
2527
if (version) {
26-
router.on(methods, url, { version }, op(updateParams))
28+
router.on(methods, url, { version }, handlers.match(updateParams))
2729
} else {
28-
router.on(methods, url, op(updateParams))
30+
router.on(methods, url, handlers.match(updateParams))
2931
}
3032
})
3133
}

0 commit comments

Comments
 (0)