mirror of
https://github.com/kurbezz/discord-bot.git
synced 2025-12-06 07:05:36 +01:00
Fix SPA
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
from fastapi.staticfiles import StaticFiles
|
|
||||||
|
|
||||||
from core.mongo import mongo_manager
|
from core.mongo import mongo_manager
|
||||||
from core.redis import redis_manager
|
from core.redis import redis_manager
|
||||||
@@ -7,6 +6,7 @@ from core.broker import broker
|
|||||||
|
|
||||||
from .auth.authx import auth
|
from .auth.authx import auth
|
||||||
from .views import routes
|
from .views import routes
|
||||||
|
from .utils.static import SPAStaticFiles
|
||||||
|
|
||||||
|
|
||||||
def get_app() -> FastAPI:
|
def get_app() -> FastAPI:
|
||||||
@@ -19,7 +19,7 @@ def get_app() -> FastAPI:
|
|||||||
|
|
||||||
app.mount(
|
app.mount(
|
||||||
"/",
|
"/",
|
||||||
StaticFiles(
|
SPAStaticFiles(
|
||||||
directory="modules/web_app/frontend",
|
directory="modules/web_app/frontend",
|
||||||
html=True
|
html=True
|
||||||
),
|
),
|
||||||
|
|||||||
15
src/modules/web_app/utils/static.py
Normal file
15
src/modules/web_app/utils/static.py
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
from fastapi.staticfiles import StaticFiles
|
||||||
|
|
||||||
|
from starlette.responses import Response
|
||||||
|
from starlette.exceptions import HTTPException
|
||||||
|
|
||||||
|
|
||||||
|
class SPAStaticFiles(StaticFiles):
|
||||||
|
async def get_response(self, path: str, scope) -> Response:
|
||||||
|
try:
|
||||||
|
return await super().get_response(path, scope)
|
||||||
|
except HTTPException:
|
||||||
|
if path.startswith("/api"):
|
||||||
|
raise
|
||||||
|
|
||||||
|
return await super().get_response("index.html", scope)
|
||||||
Reference in New Issue
Block a user