From 394d4b3c1b538b152678aad47387c9d400911b5d Mon Sep 17 00:00:00 2001 From: "Junyan Qin (Chin)" Date: Fri, 28 Mar 2025 23:46:24 +0800 Subject: [PATCH] fix: static_file sent with wrong mimetype (#1243) --- pkg/api/http/controller/main.py | 38 +++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/pkg/api/http/controller/main.py b/pkg/api/http/controller/main.py index acbfa104..70a1a546 100644 --- a/pkg/api/http/controller/main.py +++ b/pkg/api/http/controller/main.py @@ -66,8 +66,42 @@ class HTTPController: @self.quart_app.route("/") async def index(): - return await quart.send_from_directory(frontend_path, "index.html") + return await quart.send_from_directory( + frontend_path, + "index.html", + mimetype="text/html" + ) @self.quart_app.route("/") async def static_file(path: str): - return await quart.send_from_directory(frontend_path, path) + + mimetype = None + + if path.endswith(".html"): + mimetype = "text/html" + elif path.endswith(".js"): + mimetype = "application/javascript" + elif path.endswith(".css"): + mimetype = "text/css" + elif path.endswith(".png"): + mimetype = "image/png" + elif path.endswith(".jpg"): + mimetype = "image/jpeg" + elif path.endswith(".jpeg"): + mimetype = "image/jpeg" + elif path.endswith(".gif"): + mimetype = "image/gif" + elif path.endswith(".svg"): + mimetype = "image/svg+xml" + elif path.endswith(".ico"): + mimetype = "image/x-icon" + elif path.endswith(".json"): + mimetype = "application/json" + elif path.endswith(".txt"): + mimetype = "text/plain" + + return await quart.send_from_directory( + frontend_path, + path, + mimetype=mimetype + ) \ No newline at end of file