Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/fresh/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export type ListenOptions =
& {
remoteAddress?: string;
};
function createOnListen(
export function createOnListen(
basePath: string,
options: ListenOptions,
): (localAddr: Deno.NetAddr) => void {
Expand Down
19 changes: 16 additions & 3 deletions packages/fresh/src/dev/builder.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { App, type ListenOptions, setBuildCache } from "../app.ts";
import {
App,
createOnListen,
type ListenOptions,
setBuildCache,
} from "../app.ts";
import { fsAdapter } from "../fs.ts";
import * as path from "@std/path";
import * as colors from "@std/fmt/colors";
Expand Down Expand Up @@ -181,7 +186,11 @@ export class Builder<State = any> {

const appHandler = app.handler();

const devApp = new App<State>(app.config)
// Store original basePath for display purposes
const originalBasePath = app.config.basePath;

const devConfig = { ...app.config, basePath: "" };
const devApp = new App<State>(devConfig)
.use(liveReload())
.use(devErrorOverlay())
.use(automaticWorkspaceFolders(this.config.root))
Expand All @@ -200,7 +209,11 @@ export class Builder<State = any> {
// Boot in parallel to spin up the server quicker. We'll hold
// requests until the required assets are processed.
await Promise.all([
devApp.listen(options),
devApp.listen({
...options,
onListen: options.onListen ??
createOnListen(originalBasePath, options),
}),
this.#build(buildCache, true),
]);
return;
Expand Down
18 changes: 14 additions & 4 deletions packages/fresh/src/dev/builder_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ Deno.test({
const tmp = _tmp.dir;

const app = new App({ basePath: "/foo/bar" })
.get("/", () => new Response("ok"))
.get("/", () => new Response("root index"))
.get("/asdf", () => new Response("ok"));

const builder = new Builder({
Expand All @@ -450,10 +450,20 @@ Deno.test({
},
});

const res = await fetch(`${address}/foo/bar/asdf`);
// Test regular route
const res1 = await fetch(`${address}/foo/bar/asdf`);
const text1 = await res1.text();
expect(text1).toEqual("ok");

const text = await res.text();
expect(text).toEqual("ok");
// Test root index with basePath (without trailing slash)
// This was the main issue - accessing /foo/bar should work
const res2 = await fetch(`${address}/foo/bar`);
const text2 = await res2.text();
expect(res2.status).toEqual(200);
expect(text2).toEqual("root index");

// Verify original app config is not mutated by dev builder
expect(app.config.basePath).toEqual("/foo/bar");

controller.abort();
},
Expand Down
Loading