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
6 changes: 5 additions & 1 deletion src/server/dev-server/request-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ export class RequestHandler {
});

if (normalized === DEV_SERVER_ENDPOINTS.HMR_RUNTIME && this.hmrServer) {
const runtime = isHeadRequest ? null : this.getHMRRuntime();
if (isHeadRequest) {
return builder.withContentType(HTTP_CONTENT_TYPES.JS, "", HTTP_OK);
}

const runtime = this.getHMRRuntime();
if (runtime === null) {
return null;
}
Expand Down
49 changes: 49 additions & 0 deletions tests/integration/server/dev-server-handlers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,55 @@ describe(
});
});

it("responds to HEAD requests for HMR runtime", async () => {
await withTestContext("dev-server-hmr-head", async (context) => {
const { server, port } = await createTestDevServer(context, {
enableHMR: true,
hmrPort: await context.allocatePort(),
});

const response = await fetch(`http://localhost:${port}/_veryfront/hmr-runtime.js`, {
method: "HEAD",
});

assertEquals(response.status, 200);
const contentType = response.headers.get("content-type");
assert(
contentType?.startsWith("application/javascript"),
`Expected content-type to start with "application/javascript" but got "${contentType}"`,
);

// HEAD requests should not fall through to application router
assertEquals(await response.text(), "");

await server.stop();
await drainEventLoop();
});
});

it("responds to HEAD requests for error overlay runtime", async () => {
await withTestContext("dev-server-error-overlay-head", async (context) => {
const { server, port } = await createTestDevServer(context);

const response = await fetch(`http://localhost:${port}/_veryfront/error-overlay.js`, {
method: "HEAD",
});

assertEquals(response.status, 200);
const contentType = response.headers.get("content-type");
assert(
contentType?.startsWith("application/javascript"),
`Expected content-type to start with "application/javascript" but got "${contentType}"`,
);

// HEAD requests should not fall through to application router
assertEquals(await response.text(), "");

await server.stop();
await drainEventLoop();
});
});

it("handles virtual module requests", async () => {
await withTestContext("dev-server-virtual-modules", async (context) => {
const { server, port } = await createTestDevServer(context);
Expand Down
Loading