From 9d37bbcba457768eae09ee5229ade95e1bb9b49d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A2=A8=E6=A2=93=E6=9F=92?= <1787882683@qq.com> Date: Mon, 17 Nov 2025 18:19:27 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=87=AA=E5=8A=A8=E6=A3=80=E6=B5=8B?= =?UTF-8?q?=E5=B9=B6=E8=AE=BE=E7=BD=AE=E9=9D=99=E6=80=81=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E7=9A=84=20MIME=20=E7=B1=BB=E5=9E=8B=E4=BB=A5=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E7=94=9F=E4=BA=A7=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/webui/manager.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/webui/manager.py b/src/webui/manager.py index e4679f1e..9a4999ff 100644 --- a/src/webui/manager.py +++ b/src/webui/manager.py @@ -42,6 +42,14 @@ def setup_production_mode() -> bool: try: from src.common.server import get_global_server from starlette.responses import FileResponse + import mimetypes + + # 确保正确的 MIME 类型映射 + mimetypes.init() + mimetypes.add_type('application/javascript', '.js') + mimetypes.add_type('application/javascript', '.mjs') + mimetypes.add_type('text/css', '.css') + mimetypes.add_type('application/json', '.json') server = get_global_server() base_dir = Path(__file__).parent.parent.parent @@ -68,11 +76,12 @@ def setup_production_mode() -> bool: # 检查文件是否存在 file_path = static_path / full_path if file_path.is_file(): - # 直接返回文件,Starlette 会自动管理文件句柄 - return FileResponse(file_path) + # 自动检测 MIME 类型 + media_type = mimetypes.guess_type(str(file_path))[0] + return FileResponse(file_path, media_type=media_type) # 返回 index.html(SPA 路由) - return FileResponse(static_path / "index.html") + return FileResponse(static_path / "index.html", media_type="text/html") host = os.getenv("HOST", "127.0.0.1") port = os.getenv("PORT", "8000")