-
Notifications
You must be signed in to change notification settings - Fork 724
Open
Open
Copy link
Description
The following works correctly as I expect...
// main.ts
import { App } from "fresh";
export const app = new App();
app.use("/api", async (ctx) => {
console.log("Matched Middleware"); // Triggered ✓ (GET: /api/1234/endpoint)
return await ctx.next();
});
app.get("/api/:opt?/endpoint", () => {
return new Response("Hello, app routing!");
});
However, when mimicking the same setup with .fsRoutes
, it doesn't match the middleware.
// main.ts
import { App, staticFiles } from "fresh";
export const app = new App();
app.use(async (ctx) => {
console.log("Matched Middleware"); // Not Triggered ✗ (GET: /api/1234/endpoint)
return await ctx.next();
});
app.fsRoutes();
// routes/api/[[opt]]/endpoint.ts
import { define } from "../../../utils.ts";
export const handler = define.handlers({
GET() {
return new Response("Hello, file routing!");
},
});
Please note that this issue doesn't occur if using .use()
without a path (e.g. app.use(async (ctx) => {...});
). Also, it seems the the issue only occurs with optional routes (e.g. it does correctly match against api/[param]/endpoint.ts
).
It could be a misconfiguration on my part or a misunderstanding of file routing as I'm new to fresh, but this seems like an issue within Fresh itself.
To replicate run deno run -Ar jsr:@fresh/init
and add the above snippets.
Metadata
Metadata
Assignees
Labels
No labels