Gateway: serve web/ at root via StaticFiles; redirect / to /index-live.html
This commit is contained in:
parent
0fb24a8ade
commit
6dcfaffb7c
2 changed files with 14 additions and 2 deletions
|
|
@ -38,9 +38,10 @@ COPY --from=builder /opt/venv /opt/venv
|
|||
|
||||
WORKDIR /srv/app
|
||||
COPY app/ ./app/
|
||||
COPY web/ /srv/web/
|
||||
COPY scripts/entrypoint.sh /usr/local/bin/entrypoint.sh
|
||||
RUN chmod +x /usr/local/bin/entrypoint.sh \
|
||||
&& chown -R app:app /srv/app
|
||||
&& chown -R app:app /srv/app /srv/web
|
||||
|
||||
USER app
|
||||
|
||||
|
|
|
|||
13
app/main.py
13
app/main.py
|
|
@ -1,8 +1,10 @@
|
|||
from collections.abc import AsyncIterator
|
||||
from contextlib import asynccontextmanager
|
||||
from pathlib import Path
|
||||
|
||||
from fastapi import FastAPI, Request
|
||||
from fastapi.responses import JSONResponse
|
||||
from fastapi.responses import JSONResponse, RedirectResponse
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from slowapi.errors import RateLimitExceeded
|
||||
from slowapi.middleware import SlowAPIMiddleware
|
||||
|
||||
|
|
@ -15,6 +17,8 @@ from app.routers.auth import router as auth_router
|
|||
from app.routers.push import router as push_router
|
||||
from app.routers.views import router as views_router
|
||||
|
||||
WEB_DIR = Path("/srv/web")
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(_: FastAPI) -> AsyncIterator[None]:
|
||||
|
|
@ -49,4 +53,11 @@ def create_app(role: str) -> FastAPI:
|
|||
app.include_router(push_router)
|
||||
app.include_router(views_router)
|
||||
|
||||
@app.get("/", include_in_schema=False)
|
||||
async def _root() -> RedirectResponse:
|
||||
return RedirectResponse(url="/index-live.html", status_code=307)
|
||||
|
||||
if WEB_DIR.is_dir():
|
||||
app.mount("/", StaticFiles(directory=str(WEB_DIR), html=True), name="web")
|
||||
|
||||
return app
|
||||
|
|
|
|||
Loading…
Reference in a new issue