Skip to content

Commit bf450af

Browse files
fix: basePath not applied to app.route()
1 parent 41cf4ac commit bf450af

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/app.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,10 @@ export class App<State> {
301301
ensureHandler(route);
302302
middlewares.push((ctx) => renderRoute(ctx, route));
303303

304-
const routePath = route.config?.routeOverride ?? path;
304+
const routePath = mergePath(
305+
this.config.basePath,
306+
route.config?.routeOverride ?? path,
307+
);
305308

306309
if (typeof route.handler === "function") {
307310
this.#addRoute("ALL", routePath, middlewares);

src/app_test.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,3 +631,19 @@ Deno.test("App - uses notFound route on 404", async () => {
631631
res = await server.get("/thrower_2");
632632
expect(await res.text()).toEqual("error route");
633633
});
634+
635+
// Issue: https://github.com/denoland/fresh/issues/3115
636+
Deno.test("App - .route() with basePath", async () => {
637+
const app = new App({ basePath: "/foo/bar" })
638+
.route("/", { handler: () => new Response("ok") });
639+
640+
const server = new FakeServer(app.handler());
641+
642+
let res = await server.delete("/");
643+
expect(res.status).toEqual(404);
644+
res = await server.delete("/foo");
645+
expect(res.status).toEqual(404);
646+
647+
res = await server.delete("/foo/bar");
648+
expect(res.status).toEqual(200);
649+
});

0 commit comments

Comments
 (0)