From 5c9113409d3b48549f46f211cd24a39b12118e1a Mon Sep 17 00:00:00 2001 From: Justin Wind Date: Wed, 19 Jul 2023 12:17:03 -0700 Subject: [PATCH] ctx.matchedPath now stores raw route rather than processed array --- lib/router/index.js | 8 +++++++- test/lib/router.js | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) 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; -- 2.45.2