mirror of
https://git.srhtnin.garden/sarah/SaraView.git
synced 2026-10-14 10:38:11 +02:00
Added dynamic urls instead of a static ones.
This commit is contained in:
1 parent
778579c04f
commit
571dfd5378
2 files changed
+92
-6
No files matched your search
+12
-3
@@ -10,8 +10,7 @@ if str(ApplicationDirectory) not in sys.path:
|
||||
|
||||
from fastapi import Depends, FastAPI, File, HTTPException, Request, Response, UploadFile
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.responses import PlainTextResponse, StreamingResponse
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from fastapi.responses import FileResponse, PlainTextResponse, StreamingResponse
|
||||
|
||||
from Auth import CreateSession, DeleteSession, GetCurrentUser, RequireAdmin, SessionCookieName
|
||||
from BookReader import ReadBookForFile
|
||||
@@ -704,5 +703,15 @@ def DeleteThemeEndpoint(Name: str, CurrentUser: dict = Depends(GetCurrentUser))
|
||||
|
||||
|
||||
FrontendDist = ApplicationDirectory.parent / "Frontend" / "dist"
|
||||
|
||||
if FrontendDist.is_dir():
|
||||
Application.mount("/", StaticFiles(directory=str(FrontendDist), html=True), name="Frontend")
|
||||
|
||||
@Application.get("/{FullPath:path}")
|
||||
def ServeFrontendEndpoint(FullPath: str):
|
||||
CandidatePath = (FrontendDist / FullPath).resolve()
|
||||
IsWithinDist = CandidatePath == FrontendDist or FrontendDist in CandidatePath.parents
|
||||
|
||||
if FullPath and IsWithinDist and CandidatePath.is_file():
|
||||
return FileResponse(CandidatePath)
|
||||
|
||||
return FileResponse(FrontendDist / "index.html")
|
||||
Reference in new issue
Block a user