Skip to content

Commit 2f1ee2f

Browse files
committed
fix: missing api data in a route with middleware
Fixes #16
1 parent 489a10b commit 2f1ee2f

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/core/definer.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ describe("defineRoute", () => {
243243

244244
const nextJsRouteHandler = route.GET;
245245

246-
const fakeContext = { params: Promise.resolve(undefined as unknown as { id: string }) }
246+
const fakeContext = { params: Promise.resolve(undefined as unknown as { id: string }) };
247247
await nextJsRouteHandler(mockRequest as unknown as Request, fakeContext);
248248

249249
expect(console.log).toHaveBeenCalledWith(expect.stringContaining("You tried to add pathParams to a route"));

src/core/definer.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@ function defineRoute<
152152
};
153153

154154
if (input.middleware) {
155-
return { [input.method]: input.middleware(handler) } as RouteHandler<M, PPI, MwReq, MwRes>;
155+
const alteredHandler = input.middleware(handler);
156+
alteredHandler.apiData = handler.apiData;
157+
return { [input.method]: alteredHandler } as RouteHandler<M, PPI, MwReq, MwRes>;
156158
}
157159

158160
return { [input.method]: handler } as RouteHandler<M, PPI, MwReq, MwRes>;

0 commit comments

Comments
 (0)