53 lines
1.2 KiB
Python
53 lines
1.2 KiB
Python
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from starlette.responses import RedirectResponse
|
|
|
|
from app.api import health
|
|
from app.api.v1.api import api_router
|
|
from app.core.config import settings
|
|
from app.db.base import Base
|
|
from app.db.session import engine
|
|
|
|
# Create database tables
|
|
Base.metadata.create_all(bind=engine)
|
|
|
|
app = FastAPI(
|
|
title=settings.PROJECT_NAME,
|
|
openapi_url="/openapi.json",
|
|
)
|
|
|
|
# Set up CORS
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
# Include routers
|
|
app.include_router(api_router, prefix=settings.API_V1_STR)
|
|
app.include_router(health.router)
|
|
|
|
|
|
@app.get("/", tags=["root"])
|
|
async def root():
|
|
"""
|
|
Root endpoint that provides basic API information.
|
|
"""
|
|
return {"name": settings.PROJECT_NAME, "docs": "/docs", "health": "/health"}
|
|
|
|
|
|
@app.get("/docs", include_in_schema=False)
|
|
async def custom_swagger_ui_redirect():
|
|
"""
|
|
Redirect to docs
|
|
"""
|
|
return RedirectResponse(url="/docs")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
import uvicorn
|
|
|
|
uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)
|