Skip to content

Commit 2941a96

Browse files
evnchnclaude
andauthored
Fix .mjs files served with wrong MIME type (#5724)
### Motivation Fixes #5723, which boils down to how in Windows, `mimetypes` respect the Windows registry. As such under a system with `.mjs` override `Content Type` as `text/plain`, JavaScript ES modules (`.mjs` files) like `dompurify.mjs` were being served with MIME type `text/plain` instead of `text/javascript`. Compliant browsers will reject them due to strict MIME type checking for module scripts. ### Implementation Register the `.mjs` extension with the correct `text/javascript` MIME type, similar to how `.js` files are already registered. ### Progress - [x] I chose a meaningful title that completes the sentence: "If applied, this PR will..." - [x] The implementation is complete. - [x] If this PR addresses a security issue, it has been coordinated via the [security advisory](https://github.com/zauberzeug/nicegui/security/advisories/new) process. - [x] Pytests have been added (or are not necessary). - [x] Documentation has been added (or is not necessary). --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent fd18ca1 commit 2941a96

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

nicegui/nicegui.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ async def __call__(self, scope, receive, send):
5454

5555

5656
mimetypes.add_type('text/javascript', '.js')
57+
mimetypes.add_type('text/javascript', '.mjs')
5758
mimetypes.add_type('text/css', '.css')
5859

5960
static_files = CacheControlledStaticFiles(

tests/test_serving_files.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ def page():
155155
assert response.status_code == 200
156156
assert response.headers['Content-Type'].startswith('text/javascript')
157157

158+
response = httpx.get(f'http://localhost:{Screen.PORT}/_nicegui/{__version__}/static/dompurify.mjs', timeout=5)
159+
assert response.status_code == 200
160+
assert response.headers['Content-Type'].startswith('text/javascript')
161+
158162
response = httpx.get(f'http://localhost:{Screen.PORT}/_nicegui/{__version__}/static/nicegui.css', timeout=5)
159163
assert response.status_code == 200
160164
assert response.headers['Content-Type'].startswith('text/css')

0 commit comments

Comments
 (0)