From: Justin Wind Date: Wed, 19 Jul 2023 19:17:03 +0000 (-0700) Subject: ctx.matchedPath now stores raw route rather than processed array X-Git-Tag: v1.2.10~4 X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=5c9113409d3b48549f46f211cd24a39b12118e1a;p=squeep-api-dingus ctx.matchedPath now stores raw route rather than processed array --- diff --git a/lib/router/index.js b/lib/router/index.js index f0d2d94..1585065 100644 --- a/lib/router/index.js +++ b/lib/router/index.js @@ -69,6 +69,12 @@ class Router { } routePath[kPathMethods] = {}; + + Object.defineProperty(routePath, 'path', { + enumerable: false, + value: rawPath, + }); + Object.freeze(routePath); return routePath; } @@ -253,7 +259,7 @@ class Router { const { matchedPath, pathParams } = this._pathFind(pathParts); ctx.params = pathParams; if (matchedPath) { - ctx.matchedPath = matchedPath; + ctx.matchedPath = matchedPath.path; if (method in matchedPath[kPathMethods]) { return matchedPath[kPathMethods][method]; } diff --git a/test/lib/router.js b/test/lib/router.js index f9a2401..c89cc19 100644 --- a/test/lib/router.js +++ b/test/lib/router.js @@ -298,6 +298,7 @@ describe('Router', function () { const { handler } = router.lookup(method, path, ctx); assert.strictEqual(handler, stubHandler); + assert.strictEqual(ctx.matchedPath, urlPath); }); it('does not find handler with trailing slash', function () { router.ignoreTrailingSlash = false;