Skip to content

Commit 394d4b3

Browse files
authored
fix: static_file sent with wrong mimetype (#1243)
1 parent a0fd152 commit 394d4b3

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

pkg/api/http/controller/main.py

+36-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,42 @@ async def healthz():
6666

6767
@self.quart_app.route("/")
6868
async def index():
69-
return await quart.send_from_directory(frontend_path, "index.html")
69+
return await quart.send_from_directory(
70+
frontend_path,
71+
"index.html",
72+
mimetype="text/html"
73+
)
7074

7175
@self.quart_app.route("/<path:path>")
7276
async def static_file(path: str):
73-
return await quart.send_from_directory(frontend_path, path)
77+
78+
mimetype = None
79+
80+
if path.endswith(".html"):
81+
mimetype = "text/html"
82+
elif path.endswith(".js"):
83+
mimetype = "application/javascript"
84+
elif path.endswith(".css"):
85+
mimetype = "text/css"
86+
elif path.endswith(".png"):
87+
mimetype = "image/png"
88+
elif path.endswith(".jpg"):
89+
mimetype = "image/jpeg"
90+
elif path.endswith(".jpeg"):
91+
mimetype = "image/jpeg"
92+
elif path.endswith(".gif"):
93+
mimetype = "image/gif"
94+
elif path.endswith(".svg"):
95+
mimetype = "image/svg+xml"
96+
elif path.endswith(".ico"):
97+
mimetype = "image/x-icon"
98+
elif path.endswith(".json"):
99+
mimetype = "application/json"
100+
elif path.endswith(".txt"):
101+
mimetype = "text/plain"
102+
103+
return await quart.send_from_directory(
104+
frontend_path,
105+
path,
106+
mimetype=mimetype
107+
)

0 commit comments

Comments
 (0)