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
3 changes: 2 additions & 1 deletion js/server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,15 @@ class Server {

// Run after express.static: missing CSS gets a CSS-typed 404 instead of
// Express's default HTML 404, which browsers report as a MIME mismatch.
// Limited to core directories so node helper routes registered later still work.
const handleMissingStylesheet = (req, res, next) => {
if (path.extname(req.path).toLowerCase() !== ".css") {
return next();
}

res.status(404).type("text/css").send("");
};
app.use(handleMissingStylesheet);
app.use(uniqDirs, handleMissingStylesheet);

this.#server.on("listening", () => {
resolve({
Expand Down
8 changes: 8 additions & 0 deletions tests/e2e/esm_helper_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,12 @@ describe("ESM node helper", () => {
expect(res.status).toBe(200);
expect(await res.text()).toBe("pong\n");
});

it("serves stylesheets from the helper before the missing stylesheet handler", async () => {
const res = await fetch(`http://localhost:${port}/esmHelper/helper.css`);

expect(res.status).toBe(200);
expect(res.headers.get("content-type")).toMatch(/^text\/css/);
expect(await res.text()).toContain("display: block;");
});
});
3 changes: 3 additions & 0 deletions tests/mocks/esmHelper/public/helper.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.helper {
display: block;
}