Skip to content

Commit c62bdc4

Browse files
authored
fix: exclude dev-browser-sw.js from static glob (#80)
Avoid duplicate HEAD route registration when bundled web assets include the dev browser service worker. Add routing coverage and a patch changeset for @spencer-kit/coder-studio.
1 parent efe8b5e commit c62bdc4

3 files changed

Lines changed: 26 additions & 1 deletion

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@spencer-kit/coder-studio": patch
3+
---
4+
5+
Fix server startup failure when bundled web assets include `dev-browser-sw.js` by excluding the service worker from static file glob registration.

packages/server/src/app-routing.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,26 @@ describe("app routing", () => {
294294
expect(response.body).toContain("coder-studio-dev-browser-session");
295295
});
296296

297+
it("does not double-register dev-browser-sw.js when it exists in the web root", async () => {
298+
writeFileSync(join(webRoot, "dev-browser-sw.js"), 'const MARKER = "bundled-dev-browser-sw";\n');
299+
300+
const instance = await createApp();
301+
302+
const getResponse = await instance.inject({
303+
method: "GET",
304+
url: "/dev-browser-sw.js",
305+
});
306+
expect(getResponse.statusCode).toBe(200);
307+
expect(getResponse.headers["cache-control"]).toBe("no-cache, no-store, must-revalidate");
308+
expect(getResponse.body).toContain("bundled-dev-browser-sw");
309+
310+
const headResponse = await instance.inject({
311+
method: "HEAD",
312+
url: "/dev-browser-sw.js",
313+
});
314+
expect(headResponse.statusCode).toBe(200);
315+
});
316+
297317
it("serves the dev browser service worker without a configured web root", async () => {
298318
const instance = await createApp(false, {}, { webRoot: null });
299319

packages/server/src/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ export async function buildFastifyApp(deps: AppDeps): Promise<FastifyInstance> {
213213
root: deps.webRoot,
214214
prefix: "/",
215215
wildcard: false,
216-
globIgnore: ["index.html", "assets/**"],
216+
globIgnore: ["index.html", "assets/**", "dev-browser-sw.js"],
217217
maxAge: "1y",
218218
immutable: true,
219219
});

0 commit comments

Comments
 (0)