fix: set Content-Type header when preview server serves HTML#156
Merged
Conversation
The preview-server middleware in `configurePreviewServer` responded with `res.end(html)` without a `Content-Type` header, for both matched entry files and the SPA fallback. Browsers usually sniff it as HTML, but some environments and tooling won't. Set an explicit `Content-Type: text/html; charset=utf-8` before ending the response. Also collapse the two separate lookup loops (candidate files, then the `index.html`/`index.htm` SPA fallback) into a single deduplicated candidate list. Closes #142 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018H1uPDiSpxrHtQvyAxUEVC
uhyo
force-pushed
the
claude/issue-142-adhark
branch
from
July 19, 2026 10:15
b5999bc to
72d0f1b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The preview-server middleware in
packages/static/src/plugin/server.ts(configurePreviewServer) responded withres.end(html)without setting anyContent-Typeheader — for both matched entry files and the SPA fallback. Browsers generally sniff the response as HTML, but it should be explicit (and some environments/tools won't sniff).Fixes #142.
Changes
Content-Type.res.setHeader("Content-Type", "text/html; charset=utf-8")is now sent beforeres.end(html)on every served response.index.html/index.htmSPA-fallback loop are merged into a single deduplicated candidate list (new Set([...urlPathToFileCandidates(urlPath), "index.html", "index.htm"])). TheSetavoids re-readingindex.html/index.htmfor the root path, whereurlPathToFileCandidatesalready yields them.Verification
pnpm typecheck✅pnpm test:run✅pnpm lint(oxlint) ✅pnpm format:check(prettier) ✅🤖 Generated with Claude Code