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);
|
console.log("DEBUG: trying pattern, match result =", match);
|
||||||
if (match) {
|
if (match) {
|
||||||
console.log("match", match);
|
console.log("match", match);
|
||||||
const resp = await pr.handler(req);
|
const resp = await pr.handler(req, match.params);
|
||||||
|
|
||||||
return resp;
|
return resp;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ const processRoutes=(routes:Route[]) :ProcessedRoutes => {
|
|||||||
|
|
||||||
const handler: InternalHandler = async (
|
const handler: InternalHandler = async (
|
||||||
expressRequest: ExpressRequest,
|
expressRequest: ExpressRequest,
|
||||||
|
params: Record<string, string>,
|
||||||
): Promise<Result> => {
|
): Promise<Result> => {
|
||||||
const method = massageMethod(expressRequest.method);
|
const method = massageMethod(expressRequest.method);
|
||||||
|
|
||||||
@@ -47,7 +48,7 @@ const processRoutes=(routes:Route[]) :ProcessedRoutes => {
|
|||||||
pattern: route.path,
|
pattern: route.path,
|
||||||
path: expressRequest.originalUrl,
|
path: expressRequest.originalUrl,
|
||||||
method,
|
method,
|
||||||
parameters: { one: 1, two: 2 },
|
parameters: params,
|
||||||
request: expressRequest,
|
request: expressRequest,
|
||||||
user: auth.user,
|
user: auth.user,
|
||||||
session: new Session(auth.session, auth.user),
|
session: new Session(auth.session, auth.user),
|
||||||
|
|||||||
@@ -29,13 +29,13 @@ export type Call = {
|
|||||||
pattern: string;
|
pattern: string;
|
||||||
path: string;
|
path: string;
|
||||||
method: Method;
|
method: Method;
|
||||||
parameters: object;
|
parameters: Record<string, string>;
|
||||||
request: ExpressRequest;
|
request: ExpressRequest;
|
||||||
user: User;
|
user: User;
|
||||||
session: Session;
|
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 Handler = (call: Call) => Promise<Result>;
|
||||||
export type ProcessedRoute = {
|
export type ProcessedRoute = {
|
||||||
|
|||||||
Reference in New Issue
Block a user