fix: basePath not applied to app.route() (#3116)
Fixes https://github.com/denoland/fresh/issues/3115
This commit is contained in:
+4
-1
@@ -301,7 +301,10 @@ export class App<State> {
|
|||||||
ensureHandler(route);
|
ensureHandler(route);
|
||||||
middlewares.push((ctx) => renderRoute(ctx, route));
|
middlewares.push((ctx) => renderRoute(ctx, route));
|
||||||
|
|
||||||
const routePath = route.config?.routeOverride ?? path;
|
const routePath = mergePath(
|
||||||
|
this.config.basePath,
|
||||||
|
route.config?.routeOverride ?? path,
|
||||||
|
);
|
||||||
|
|
||||||
if (typeof route.handler === "function") {
|
if (typeof route.handler === "function") {
|
||||||
this.#addRoute("ALL", routePath, middlewares);
|
this.#addRoute("ALL", routePath, middlewares);
|
||||||
|
|||||||
@@ -631,3 +631,23 @@ Deno.test("App - uses notFound route on 404", async () => {
|
|||||||
res = await server.get("/thrower_2");
|
res = await server.get("/thrower_2");
|
||||||
expect(await res.text()).toEqual("error route");
|
expect(await res.text()).toEqual("error route");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Issue: https://github.com/denoland/fresh/issues/3115
|
||||||
|
Deno.test("App - .route() with basePath", async () => {
|
||||||
|
const app = new App({ basePath: "/foo/bar" })
|
||||||
|
.route("/", { handler: () => new Response("ok") });
|
||||||
|
|
||||||
|
const server = new FakeServer(app.handler());
|
||||||
|
|
||||||
|
let res = await server.delete("/");
|
||||||
|
await res.body?.cancel();
|
||||||
|
expect(res.status).toEqual(404);
|
||||||
|
|
||||||
|
res = await server.delete("/foo");
|
||||||
|
await res.body?.cancel();
|
||||||
|
expect(res.status).toEqual(404);
|
||||||
|
|
||||||
|
res = await server.delete("/foo/bar");
|
||||||
|
expect(await res.text()).toEqual("ok");
|
||||||
|
expect(res.status).toEqual(200);
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user