Skip to content

Commit 37382a3

Browse files
committed
Simpler access to router path.
1 parent e4f67bf commit 37382a3

2 files changed

Lines changed: 4 additions & 11 deletions

File tree

lib/index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,8 @@ function captureRouteMethod(caseSensitive, ignoreTrailingSlash, ctx, routeOption
7979
}
8080
function handleRequest(ctx, request, reply, done) {
8181
const { routeMethods, matcherRoutes, send405 } = ctx;
82-
let { url, method,
83-
// @ts-ignore request does not have context in it's type declaration
84-
context: { config: { url: path = findUrlRoute(matcherRoutes, url) } } } = request;
85-
const methods = routeMethods.get(path);
82+
let { url, method, routerPath = findUrlRoute(matcherRoutes, url) || "" } = request;
83+
const methods = routeMethods.get(routerPath);
8684
if (methods) {
8785
reply.header("allow", methods);
8886
if (send405 && !methods.includes(method)) {

src/index.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,10 @@ function handleRequest(ctx: AllowContext,
131131
let {
132132
url,
133133
method,
134-
// @ts-ignore request does not have context in it's type declaration
135-
context: {
136-
config: {
137-
url: path = findUrlRoute(matcherRoutes, url)
138-
}
139-
}
134+
routerPath = findUrlRoute(matcherRoutes, url) || ""
140135
} = request
141136

142-
const methods = routeMethods.get(path)
137+
const methods = routeMethods.get(routerPath)
143138

144139
if (methods) {
145140
reply.header("allow", methods)

0 commit comments

Comments
 (0)