Skip to content

Commit

Permalink
TEMP: mount static files
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisLovering committed Aug 19, 2024
1 parent 9d54367 commit c9165ee
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion thallium-backend/src/app.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,53 @@
import logging
import time
import typing as t
from collections.abc import Awaitable, Callable

from fastapi import FastAPI, Request, Response
from fastapi.exceptions import RequestValidationError
from fastapi.openapi.utils import get_openapi
from fastapi.responses import JSONResponse
from fastapi.staticfiles import StaticFiles

from src.routes import top_level_router
from src.settings import CONFIG

log = logging.getLogger(__name__)

fastapi_app = FastAPI(debug=CONFIG.debug, root_path=CONFIG.app_prefix)
fastapi_app = FastAPI(
debug=CONFIG.debug,
root_path=CONFIG.app_prefix,
docs_url=None,
redoc_url=None,
)
fastapi_app.mount("/static", StaticFiles(directory="src/static"), name="static")
fastapi_app.include_router(top_level_router)


def custom_openapi() -> dict[str, t.Any]:
"""Create a custom OpenAPI schema."""
if fastapi_app.openapi_schema:
return fastapi_app.openapi_schema
openapi_schema = get_openapi(
title="Pixels API",
description=None,
routes=fastapi_app.routes,
version="0.0.1",
)
fastapi_app.openapi_schema = openapi_schema
return fastapi_app.openapi_schema


fastapi_app.openapi = custom_openapi


@fastapi_app.get("/docs", include_in_schema=False)
async def docs(request: Request) -> Response:
"""Return the API docs."""
template_name = "docs.html"
return CONFIG.templates.TemplateResponse(template_name, {"request": request})


@fastapi_app.get("/heartbeat")
def health_check() -> JSONResponse:
"""Return basic response, for use as a health check."""
Expand Down

0 comments on commit c9165ee

Please sign in to comment.