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:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user