fixes handlers not being compatible with deno handlers
This commit is contained in:
parent
05831b364b
commit
67ddb71fdd
@ -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": [
|
||||
|
@ -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);
|
||||
});
|
||||
|
||||
|
@ -6,7 +6,7 @@ interface RouterContext {
|
||||
request: Request;
|
||||
}
|
||||
|
||||
type Handler = (ctx: RouterContext) => Promise<Response> | Response;
|
||||
type Handler = (req: Request, ctx: RouterContext) => Promise<Response> | Response;
|
||||
type Middleware = (ctx: RouterContext, next: () => Promise<Response>) => Promise<Response>;
|
||||
|
||||
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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user