diff --git a/deno.json b/deno.json index c4d6b01..abec100 100644 --- a/deno.json +++ b/deno.json @@ -1,7 +1,7 @@ { "name": "@bearmetal/router", "description": "A simple router for Deno", - "version": "0.1.0", + "version": "0.1.1", "stable": true, "repository": "https://github.com/emmaos/bearmetal", "files": [ diff --git a/router.test.ts b/router.test.ts index 66d1650..11f6c2d 100644 --- a/router.test.ts +++ b/router.test.ts @@ -49,7 +49,7 @@ describe("Router", () => { describe("Route Parameters", () => { it("should handle route parameters", async () => { router.route("/users/:id") - .get(async (ctx) => new Response(ctx.params.id)); + .get(async (_, ctx) => new Response(ctx.params.id)); const req = new Request("http://localhost/users/123", { method: "GET", @@ -61,7 +61,7 @@ describe("Router", () => { it("should handle multiple route parameters", async () => { router.route("/users/:userId/posts/:postId") - .get(async (ctx) => { + .get(async (_, ctx) => { return new Response(JSON.stringify(ctx.params)); }); @@ -182,7 +182,7 @@ describe("Router", () => { it("should handle nested routes with parameters", async () => { const apiRouter = new Router(); apiRouter.route("/users/:id") - .get(async (ctx) => new Response(ctx.params.id)); + .get(async (_, ctx) => new Response(ctx.params.id)); router.use("/api/:version", apiRouter); @@ -225,7 +225,7 @@ describe("Router", () => { }); router.route("/test") - .get(async (ctx) => { + .get(async (_, ctx) => { return new Response(ctx.state.test as string); }); diff --git a/router.ts b/router.ts index ed481ba..3ebfc21 100644 --- a/router.ts +++ b/router.ts @@ -6,7 +6,7 @@ interface RouterContext { request: Request; } -type Handler = (ctx: RouterContext) => Promise | Response; +type Handler = (req: Request, ctx: RouterContext) => Promise | Response; type Middleware = (ctx: RouterContext, next: () => Promise) => Promise; interface RouteConfig { @@ -247,7 +247,7 @@ export class Router { return await middleware.handler(middlewareCtx, executeMiddleware); } // Final handler gets the accumulated parameters - return await handler(baseCtx); + return await handler(req, baseCtx); }; try {