Skip to content

Commit

Permalink
fix: Docs are rendered properly (#201) (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
gromdimon authored Nov 13, 2023
1 parent 187cba8 commit 2119aa6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
2 changes: 2 additions & 0 deletions backend/app/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class Settings(BaseSettings):
DEBUG: bool = False
#: Project name
PROJECT_NAME: str = "REEV"
#: Path to frontend build, if any.
SERVE_FRONTEND: str | None = ""
#: Path to REEV version file.
VERSION_FILE: str = "/VERSION"
#: The REEV version from the file (``None`` if to load dynamically from git)
Expand Down
23 changes: 21 additions & 2 deletions backend/app/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import logging
import pathlib
from contextlib import asynccontextmanager

from fastapi import FastAPI
from fastapi import FastAPI, Request
from fastapi.staticfiles import StaticFiles
from starlette.middleware.cors import CORSMiddleware
from starlette.responses import FileResponse

Expand Down Expand Up @@ -38,12 +40,29 @@
app.include_router(api_v1_router, prefix=settings.API_V1_STR)


@app.on_event("startup")
@asynccontextmanager
async def create_superuser_on_startup():
await create_superuser()
yield


@app.get("/favicon.ico", include_in_schema=False)
async def favicon():
"""Serve favicon"""
return FileResponse(pathlib.Path(__file__).parent / "assets/favicon.ico")


if settings.SERVE_FRONTEND: # pragma: no cover
logging.info(f"serving front-end from {settings.SERVE_FRONTEND}")
app.mount("/assets", StaticFiles(directory=f"{settings.SERVE_FRONTEND}/assets"), name="ui")

@app.get("/")
async def index():
"""Render the index.html page at the root URL"""
return FileResponse(f"{settings.SERVE_FRONTEND}/index.html")

@app.api_route("/{path_name:path}", methods=["GET"])
async def catch_all(request: Request, path_name: str):
"""Catch-all route forwarding to frontend."""
_, _ = request, path_name
return FileResponse(f"{settings.SERVE_FRONTEND}/index.html")

0 comments on commit 2119aa6

Please sign in to comment.