added mime typing

This commit is contained in:
Saifeddine ALOUI 2024-06-06 23:19:03 +02:00
parent e7e4bb8d21
commit 9179494972
2 changed files with 14 additions and 1 deletions

13
app.py
View File

@ -7,6 +7,7 @@ This file is the entry point to the webui.
""" """
from fastapi import FastAPI from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles from fastapi.staticfiles import StaticFiles
from starlette.responses import FileResponse
from fastapi.responses import HTMLResponse from fastapi.responses import HTMLResponse
from lollms.app import LollmsApplication from lollms.app import LollmsApplication
from lollms.paths import LollmsPaths from lollms.paths import LollmsPaths
@ -222,6 +223,18 @@ if __name__ == "__main__":
app.mount("/extensions", StaticFiles(directory=Path(__file__).parent/"web"/"dist", html=True), name="extensions") app.mount("/extensions", StaticFiles(directory=Path(__file__).parent/"web"/"dist", html=True), name="extensions")
app.mount("/playground", StaticFiles(directory=Path(__file__).parent/"web"/"dist", html=True), name="playground") app.mount("/playground", StaticFiles(directory=Path(__file__).parent/"web"/"dist", html=True), name="playground")
app.mount("/settings", StaticFiles(directory=Path(__file__).parent/"web"/"dist", html=True), name="settings") app.mount("/settings", StaticFiles(directory=Path(__file__).parent/"web"/"dist", html=True), name="settings")
# Custom route to serve JavaScript files with the correct MIME type
@app.get("/{path:path}")
async def serve_js(path: str):
if path=="":
return FileResponse(Path(__file__).parent / "web" / "dist" / "index.html", media_type="text/html")
file_path = Path(__file__).parent / "web" / "dist" / path
if file_path.suffix == ".js":
return FileResponse(file_path, media_type="application/javascript")
return FileResponse(file_path)
app.mount("/", StaticFiles(directory=Path(__file__).parent/"web"/"dist", html=True), name="static") app.mount("/", StaticFiles(directory=Path(__file__).parent/"web"/"dist", html=True), name="static")

@ -1 +1 @@
Subproject commit 654ebcfb32819d5418a5622460b602d77daf3eb9 Subproject commit 0a10f39fe33d6a40e47be79b3634224c75ab2130