diff options
-rw-r--r-- | src/hero.mjs | 9 | ||||
-rw-r--r-- | tests/js/hero.mjs | 5 |
2 files changed, 12 insertions, 2 deletions
diff --git a/src/hero.mjs b/src/hero.mjs index daf8141..10fa06e 100644 --- a/src/hero.mjs +++ b/src/hero.mjs @@ -172,12 +172,17 @@ export const addRoute = (table, methods, path, handlerFn) => { return addRoute(table, [methods], path, handlerFn); } - assert.ok(methods.every(m => HTTP_METHODS.has(m))); + assert.ok(methods.every(isValidLabel)); const segments = pathToSegments(path); const kw = hasPathParams(segments) ? "dynamic" : "static"; return methods.reduce( - (acc, el) => u.assocIn(acc, [kw, el].concat(segments), handlerFn), + (acc, el) => + u.assocIn( + acc, + comboForLabel(el, kw).concat(segments), + handlerFn, + ), table, ); }; diff --git a/tests/js/hero.mjs b/tests/js/hero.mjs index 627aa33..f964a88 100644 --- a/tests/js/hero.mjs +++ b/tests/js/hero.mjs @@ -663,6 +663,11 @@ const test_addRoute = async t => { ); assert.deepEqual( + addRoute({}, "WEBSOCKET", "/socket", fn1), + { websocket: { GET: { socket: { "": fn1 }}}}, + ); + + assert.deepEqual( addRoute({}, ["PUT", "PATCH"], "/api/org/:orgid/member/:memberid", fn1), { dynamic: { |