fix: incorrect middleware ordering (#3102)
This is a regression introduced in https://github.com/denoland/fresh/pull/3086
This commit is contained in:
+1
-1
@@ -243,7 +243,7 @@ export class App<State> {
|
|||||||
fns = middlewares;
|
fns = middlewares;
|
||||||
}
|
}
|
||||||
|
|
||||||
const segment = getOrCreateSegment(this.#root, path, false);
|
const segment = getOrCreateSegment(this.#root, path, true);
|
||||||
segment.middlewares.push(...fns);
|
segment.middlewares.push(...fns);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
@@ -1512,3 +1512,37 @@ Deno.test("fsRoutes - warn on _layout handler", async () => {
|
|||||||
expect.any(String),
|
expect.any(String),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Middleware issue in 2.0.0-alpha.40
|
||||||
|
Deno.test("fsRoutes - call correct middleware", async () => {
|
||||||
|
const server = await createServer<{ text: string }>({
|
||||||
|
"routes/_middleware.ts": {
|
||||||
|
handler: async function middleware(ctx) {
|
||||||
|
ctx.state.text = "_middleware";
|
||||||
|
return await ctx.next();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"routes/index.ts": {
|
||||||
|
default: async (ctx) => await new Response(ctx.state.text),
|
||||||
|
},
|
||||||
|
"routes/admin/_middleware.ts": {
|
||||||
|
handler: async function adminMiddleware(ctx) {
|
||||||
|
ctx.state.text += "admin/_middleware";
|
||||||
|
return await ctx.next();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"routes/foo/index.ts": {
|
||||||
|
handler: (ctx) => {
|
||||||
|
return new Response(ctx.state.text);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
let res = await server.get("/");
|
||||||
|
let text = await res.text();
|
||||||
|
expect(text).toEqual("_middleware");
|
||||||
|
|
||||||
|
res = await server.get("/foo");
|
||||||
|
text = await res.text();
|
||||||
|
expect(text).toEqual("_middleware");
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user