Fixed Issue

This commit is contained in:
nicco 2017-08-24 18:32:23 +02:00
parent 6dd2943f68
commit 2705b4848b

View File

@ -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