mirror of
https://github.com/cupcakearmy/koa-router.git
synced 2024-12-22 16:16:29 +00:00
Fixed Issue
This commit is contained in:
parent
6dd2943f68
commit
2705b4848b
25
Router.js
25
Router.js
@ -116,9 +116,9 @@ function mkRouter(options, builder) {
|
|||||||
|
|
||||||
// Add the value into the object of GET, POST, etc.
|
// Add the value into the object of GET, POST, etc.
|
||||||
const current = routes.get(key) || {}
|
const current = routes.get(key) || {}
|
||||||
let obj = {}
|
routes.set(key, Object.assign(current, {
|
||||||
obj[method] = data
|
[method]: data
|
||||||
routes.set(key, Object.assign(current, obj))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build the routes, including the nested ones
|
// Build the routes, including the nested ones
|
||||||
@ -147,9 +147,24 @@ function chooseFn(routes, path, method) {
|
|||||||
let route = null
|
let route = null
|
||||||
if (candidates.size === 1)
|
if (candidates.size === 1)
|
||||||
route = candidates.entries().next().value[1]
|
route = candidates.entries().next().value[1]
|
||||||
else if (candidates.size > 1)
|
else if (candidates.size > 1) {
|
||||||
// TODO route chooser
|
// If more than 1 route matches, choose the most logical fit
|
||||||
|
|
||||||
|
let testPath = ''
|
||||||
|
console.log(path)
|
||||||
|
for (let i = 0; i < path.length; ++i) {
|
||||||
|
if (candidates.size < 2)
|
||||||
|
// Only 1 route left
|
||||||
|
break
|
||||||
|
|
||||||
|
testPath += path[i]
|
||||||
|
for (const entry of candidates)
|
||||||
|
if (entry[0].test(testPath))
|
||||||
|
candidates.delete(entry[0])
|
||||||
|
}
|
||||||
|
|
||||||
route = candidates.entries().next().value[1]
|
route = candidates.entries().next().value[1]
|
||||||
|
}
|
||||||
if (route === null)
|
if (route === null)
|
||||||
return defaultResponse
|
return defaultResponse
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user