yangzhitao
feat: integrate FastAPI backend and health check functionality
b4929ca
raw
history blame
863 Bytes
from fastapi import FastAPI, Request
from fastapi.responses import RedirectResponse
from fastapi.routing import APIRoute
from .config import settings
from .routes.main import api_router
def create_app() -> FastAPI:
app = FastAPI(
title="Leaderboard API",
description="API for the Leaderboard",
version="0.1.0",
docs_url=f"{settings.API_V1_STR}/docs",
openapi_url=f"{settings.API_V1_STR}/openapi.json",
generate_unique_id_function=custom_generate_unique_id,
)
app.include_router(api_router, prefix=settings.API_V1_STR)
app.add_route("/", _redirect_to_docs, methods=["GET"])
return app
def custom_generate_unique_id(route: APIRoute) -> str:
return f"{route.tags[0]}-{route.name}"
async def _redirect_to_docs(_: Request):
return RedirectResponse(url=f"{settings.API_V1_STR}/docs")