Skip to content

Commit

Permalink
Merge pull request #1594 from thetableman/dynamic-properties-fix
Browse files Browse the repository at this point in the history
Dynamic properties mimetype fix
  • Loading branch information
falkoschindler authored Sep 18, 2023
2 parents d7c7b80 + a08f15c commit 037c3f1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions nicegui/nicegui.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import mimetypes
import time
import urllib.parse
from pathlib import Path
Expand Down Expand Up @@ -26,6 +27,9 @@
socket_manager = SocketManager(app=app, mount_location='/_nicegui_ws/', json=json)
globals.sio = sio = socket_manager._sio # pylint: disable=protected-access

mimetypes.add_type('text/javascript', '.js')
mimetypes.add_type('text/css', '.css')

app.add_middleware(GZipMiddleware)
app.add_middleware(RedirectWithPrefixMiddleware)
static_files = StaticFiles(
Expand Down
13 changes: 13 additions & 0 deletions tests/test_serving_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import httpx
import pytest
import requests

from nicegui import app, ui

Expand Down Expand Up @@ -81,3 +82,15 @@ def test_auto_serving_file_from_video_source(screen: Screen):
video = screen.find_by_tag('video')
assert '/_nicegui/auto/media/' in video.get_attribute('src')
assert_video_file_streaming(video.get_attribute('src'))


def test_mimetypes_of_static_files(screen: Screen):
screen.open('/')

response = requests.get(f'http://localhost:{Screen.PORT}/_nicegui/0.1.0/static/vue.global.js', timeout=5)
assert response.status_code == 200
assert response.headers['Content-Type'].startswith('text/javascript')

response = requests.get(f'http://localhost:{Screen.PORT}/_nicegui/0.1.0/static/nicegui.css', timeout=5)
assert response.status_code == 200
assert response.headers['Content-Type'].startswith('text/css')

0 comments on commit 037c3f1

Please sign in to comment.