Skip to content
Myr

Fixed bugs

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Yusuke Wada · committed by Yusuke Wada · parent 1d32618 · Browse files · 4 files+34 added−14 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+34 added−14 removed

  • tests:+17 added−0 removed
  • other:+17 added−14 removed

4 files+34 added−14 removed

modified:example/basic/index.js+6 added-1 removed
modified:src/hono.js-2 removed
modified:src/node.js+11 added-11 removed
7 unmodified lines
8}910class Node {11 constructor({ method, label, handler, children } = {}) {12 this.label = label || '/'12 this.label = label || ''13 this.children = children || []14 this.method = {}15 if (method && handler) {16 this.method[method] = handler
8 unmodified lines
25 if (nextNode) {26 curNode = nextNode27 } else {28 curNode.children[p] = new Node({29 method: method,29 label: p,30 handler: handler,31 })32 curNode = curNode.children[p]33 }34 }36 // XXX35 if (!curNode.method[method]) {36 curNode.method[method] = handler37 }38 }
25 unmodified lines
64 }65 }6667 search(method, path) {70 if (71 path === '/' &&72 this.label === '/' &&73 Object.keys(this.method).length == 074 ) {75 return this.noRoute()76 }7768 let curNode = this69 const params = {}7071 if (path === '/') {72 const root = this.children['/']73 if (!root.method[method]) {74 return this.noRoute()75 }76 }7778 for (const p of this.splitPath(path)) {79 let nextNode = curNode.children[p]8081 if (nextNode) {82 curNode = nextNode83 continue84 }8586 let isParamMatch = false87 for (const key in curNode.children) {88 if (key === '*') {89 // Wildcard
38 unmodified lines
added:src/node.root.test.js+17 added