Replace mounted fastapi-admin with plain FastAPI admin router
This commit is contained in:
26
app/main.py
26
app/main.py
@@ -15,9 +15,12 @@ from typing import AsyncGenerator
|
||||
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from starlette.responses import RedirectResponse
|
||||
from starlette.status import HTTP_303_SEE_OTHER
|
||||
|
||||
from app.admin_web import (
|
||||
configure_admin_web,
|
||||
router as admin_web_router,
|
||||
shutdown_admin_web,
|
||||
)
|
||||
from app.core.config import get_settings
|
||||
from app.database import close_db, init_db
|
||||
from app.routers import (
|
||||
@@ -43,17 +46,13 @@ async def lifespan(app: FastAPI) -> AsyncGenerator[None, None]:
|
||||
# Startup: Initialize database
|
||||
await init_db()
|
||||
if settings.ENABLE_ADMIN:
|
||||
from app.admin import configure_admin_app
|
||||
|
||||
await configure_admin_app()
|
||||
await configure_admin_web()
|
||||
|
||||
yield
|
||||
|
||||
# Shutdown: Close database connections
|
||||
if settings.ENABLE_ADMIN:
|
||||
from app.admin import shutdown_admin_app
|
||||
|
||||
await shutdown_admin_app()
|
||||
await shutdown_admin_web()
|
||||
await close_db()
|
||||
|
||||
|
||||
@@ -177,21 +176,12 @@ app.include_router(
|
||||
)
|
||||
|
||||
if settings.ENABLE_ADMIN:
|
||||
from app.admin import admin as admin_app
|
||||
|
||||
@app.get("/admin", include_in_schema=False)
|
||||
async def admin_entrypoint():
|
||||
# Avoid Starlette mount slash-normalization redirect, which can emit an
|
||||
# absolute URL based on proxy headers such as https://127.0.0.1/admin/.
|
||||
return RedirectResponse(url="/admin/", status_code=HTTP_303_SEE_OTHER)
|
||||
|
||||
app.include_router(
|
||||
ai_router,
|
||||
prefix=f"{settings.API_V1_STR}",
|
||||
)
|
||||
|
||||
# Mount FastAPI Admin panel
|
||||
app.mount("/admin", admin_app)
|
||||
app.include_router(admin_web_router)
|
||||
|
||||
# Include admin API router for custom actions
|
||||
app.include_router(
|
||||
|
||||
Reference in New Issue
Block a user