Repository navigation
Fix #49: Serve UI JS with correct MIME type on Windows - #317
zwanski-start wants to merge 1 commit into
Conversation
Python's mimetypes reads the Windows registry, which on some machines maps .js to text/plain, so browsers refuse the UI's module scripts and the page renders blank. Register correct types for js/mjs/css/svg/json/wasm at server startup so they override registry entries. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🔍 QA report: ✅ PassedTester: Guido (cubefarm agent, in a fresh session) · Round: 1 · Author: Dennis The PR overrides MIME types for .js/.mjs/.css/.svg/.json/.wasm in server/main.py at import time, so a bad Windows registry mapping can no longer make the server send UI assets as text/plain. With a bad mapping simulated (.js and .css set to text/plain before import), master still served CSS as text/plain and the UI rendered unstyled, while the PR served correct types and the UI rendered fully with no console errors. Note: master already had a .js-only workaround in server/routers/settings.py:18 (now redundant), so the PR's real gain is the CSS/SVG/etc. coverage in one place. Lint, the new regression test, the security tests and the UI build pass; the 21 pytest failures and 25 mypy errors are the same on master.
🧪 Commands run
No browser screenshots were taken in this round. Posted by cubefarm · merges automatically once GitHub's checks pass |
Adaptation: AutoForgeAI#317 (issue AutoForgeAI#49) is covered by this change: its .css/.mjs/.svg/.json/.wasm lines are all in WEB_MIME_TYPES, and its importlib.reload test is dropped. Integrates AutoForgeAI#256 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AeH26pcsqoxPb3CDs8g1VN
Problem
On some Windows machines the registry maps
.jstotext/plain. Python'smimetypesmodule reads the registry, so Starlette'sStaticFiles/FileResponseserve the Vite bundle astext/plainand the browser refuses to run the module script, which leaves a blank page.Fix
server/main.pynow callsmimetypes.add_typeat import time for.js/.mjs(text/javascript),.css,.svg,.jsonand.wasm.add_typeinitializes the mimetypes DB first (registry included) and then overrides it, so these mappings always win.Verification
test_mime_types.pyfakes a bad registry mapping (.js→text/plain), reloadsserver.main, and asserts the correct types are restored. It passes.content-type: text/javascript; charset=utf-8.ruff checkpasses.mypyreports no errors in the changed files; the existing errors in other files are untouched.Assumptions
Closes #49
🤖 Generated with Claude Code