Skip to content

fix: set Content-Type header when preview server serves HTML#156

Merged
uhyo merged 1 commit into
masterfrom
claude/issue-142-adhark
Jul 19, 2026
Merged

fix: set Content-Type header when preview server serves HTML#156
uhyo merged 1 commit into
masterfrom
claude/issue-142-adhark

Conversation

@uhyo

@uhyo uhyo commented Jul 19, 2026

Copy link
Copy Markdown
Owner

Problem

The preview-server middleware in packages/static/src/plugin/server.ts (configurePreviewServer) responded with res.end(html) without setting any Content-Type header — 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

  • Set an explicit Content-Type. res.setHeader("Content-Type", "text/html; charset=utf-8") is now sent before res.end(html) on every served response.
  • Collapse the two lookup loops into one. The candidate-file loop and the separate index.html/index.htm SPA-fallback loop are merged into a single deduplicated candidate list (new Set([...urlPathToFileCandidates(urlPath), "index.html", "index.htm"])). The Set avoids re-reading index.html/index.htm for the root path, where urlPathToFileCandidates already yields them.

Verification

  • pnpm typecheck
  • pnpm test:run
  • pnpm lint (oxlint) ✅
  • pnpm format:check (prettier) ✅

🤖 Generated with Claude Code

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
uhyo force-pushed the claude/issue-142-adhark branch from b5999bc to 72d0f1b Compare July 19, 2026 10:15
@uhyo
uhyo merged commit e16f2c8 into master Jul 19, 2026
2 checks passed
@uhyo
uhyo deleted the claude/issue-142-adhark branch July 19, 2026 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Preview middleware serves HTML without a Content-Type header

2 participants