Pass URL parameters from path-to-regexp match into Call.parameters

Call.parameters was hardcoded to a placeholder object. Now the matched
route parameters are threaded through from the dispatcher to the handler
so handlers can access e.g. call.parameters.word.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-08 13:57:41 -05:00
parent 5be7b84972
commit f0aca17a0a
3 changed files with 5 additions and 4 deletions

View File

@@ -61,7 +61,7 @@ const makeApp = ({routes, processTitle}: MakeAppArgs) => {
console.log("DEBUG: trying pattern, match result =", match);
if (match) {
console.log("match", match);
const resp = await pr.handler(req);
const resp = await pr.handler(req, match.params);
return resp;
}

View File

@@ -29,6 +29,7 @@ const processRoutes=(routes:Route[]) :ProcessedRoutes => {
const handler: InternalHandler = async (
expressRequest: ExpressRequest,
params: Record<string, string>,
): Promise<Result> => {
const method = massageMethod(expressRequest.method);
@@ -47,7 +48,7 @@ const processRoutes=(routes:Route[]) :ProcessedRoutes => {
pattern: route.path,
path: expressRequest.originalUrl,
method,
parameters: { one: 1, two: 2 },
parameters: params,
request: expressRequest,
user: auth.user,
session: new Session(auth.session, auth.user),

View File

@@ -29,13 +29,13 @@ export type Call = {
pattern: string;
path: string;
method: Method;
parameters: object;
parameters: Record<string, string>;
request: ExpressRequest;
user: User;
session: Session;
};
export type InternalHandler = (req: ExpressRequest) => Promise<Result>;
export type InternalHandler = (req: ExpressRequest, params: Record<string, string>) => Promise<Result>;
export type Handler = (call: Call) => Promise<Result>;
export type ProcessedRoute = {