diff --git a/README.md b/README.md index d993c42..8888560 100644 --- a/README.md +++ b/README.md @@ -131,8 +131,8 @@ Also, many handlers may also accept additional arguments beyond the first ### Argument shunting -Most of the `by*` helpers will pass arguments on as is, or shunt the -arguments along if they want to introduce their own, so for example, +Most of the `by*` helpers will pass arguments on as is, or shunt the arguments +along if they want to introduce their own, so for example, `byPattern(pattern, handler)` returns a handler with the type: ```ts diff --git a/lib/by_pattern.ts b/lib/by_pattern.ts index acca6fa..10d38e1 100644 --- a/lib/by_pattern.ts +++ b/lib/by_pattern.ts @@ -17,12 +17,13 @@ export function byPattern( ...args: A ) => Awaitable, ) { - return async (req: Request, ...args: A) => { - const patterns = Array.isArray(pattern) ? pattern : [pattern]; - const url = new URL(req.url); + const patterns = Array.isArray(pattern) + ? pattern.map(asURLPattern) + : [asURLPattern(pattern)]; + return async (req: Request, ...args: A) => { for (const pattern of patterns) { - const match = asURLPattern(pattern).exec(url); + const match = pattern.exec(req.url); if (match) { const res = await handler(req, match, ...args);