diff --git a/src/bun.js/api/server.zig b/src/bun.js/api/server.zig index 4f44e4f582..b68a024f58 100644 --- a/src/bun.js/api/server.zig +++ b/src/bun.js/api/server.zig @@ -2646,7 +2646,13 @@ pub fn NewServer(protocol_enum: enum { http, https }, development_kind: enum { d ServerConfig.applyStaticRoute(any_server, ssl_enabled, app, *FileRoute, file_route, entry.path, entry.method); }, .directory => |directory_route| { - ServerConfig.applyStaticRoute(any_server, ssl_enabled, app, *DirectoryRoute, directory_route, entry.path, entry.method); + // For directory routes, we need to handle all sub-paths, so append /* to the path + const dir_path = if (std.mem.eql(u8, entry.path, "/")) + std.fmt.allocPrint(bun.default_allocator, "/*", .{}) catch bun.outOfMemory() + else + std.fmt.allocPrint(bun.default_allocator, "{s}/*", .{entry.path}) catch bun.outOfMemory(); + defer bun.default_allocator.free(dir_path); + ServerConfig.applyStaticRoute(any_server, ssl_enabled, app, *DirectoryRoute, directory_route, dir_path, entry.method); }, .html => |html_bundle_route| { ServerConfig.applyStaticRoute(any_server, ssl_enabled, app, *HTMLBundle.Route, html_bundle_route.data, entry.path, entry.method); diff --git a/test/js/bun/http/directory-route-debug.test.ts b/test/js/bun/http/directory-route-debug.test.ts new file mode 100644 index 0000000000..5f788d6897 --- /dev/null +++ b/test/js/bun/http/directory-route-debug.test.ts @@ -0,0 +1,50 @@ +import { describe, it, expect, beforeAll, afterAll } from "bun:test"; +import { bunEnv, bunExe, tempDirWithFiles, isWindows } from "harness"; +import { join } from "path"; +import { readdirSync } from "fs"; + +describe("DirectoryRoute Debug", () => { + let testDir: string; + + beforeAll(() => { + testDir = tempDirWithFiles("directory-route-debug", { + "test.html": "Test Content", + }); + console.log("Debug Test directory:", testDir); + console.log("Files in directory:", readdirSync(testDir)); + }); + + it("should debug single file serving", async () => { + const server = Bun.serve({ + port: 0, + routes: { + "/": { dir: testDir }, + }, + }); + + console.log("Server started on port:", server.port); + console.log("Testing file at path: /test.html"); + + try { + const response = await fetch(`http://localhost:${server.port}/test.html`); + console.log("Response status:", response.status); + console.log("Response headers:", Object.fromEntries(response.headers.entries())); + + if (response.status !== 200) { + const text = await response.text(); + console.log("Response body:", text); + + // Also test if file exists directly + const testFilePath = join(testDir, "test.html"); + console.log("Direct file check:", Bun.file(testFilePath).size); + } else { + const text = await response.text(); + console.log("Success! Response body:", text); + } + + expect(response.status).toBe(200); + } finally { + server.stop(); + } + }); +}); \ No newline at end of file