67 lines
1.9 KiB
Python
67 lines
1.9 KiB
Python
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from slowapi import _rate_limit_exceeded_handler
|
|
from slowapi.errors import RateLimitExceeded
|
|
|
|
from app.api.router import api_router
|
|
from app.core.config import settings
|
|
from app.core.limiter import limiter
|
|
from app.core.database import engine, Base
|
|
from app.models import module # Ensure models are loaded
|
|
|
|
# Create tables
|
|
Base.metadata.create_all(bind=engine)
|
|
|
|
from fastapi.staticfiles import StaticFiles
|
|
from app.api.endpoints import auth
|
|
from app.api import admin_backend
|
|
|
|
def create_application() -> FastAPI:
|
|
# Disable docs and redoc in production
|
|
docs_url = "/docs" if settings.ENVIRONMENT == "development" else None
|
|
redoc_url = "/redoc" if settings.ENVIRONMENT == "development" else None
|
|
|
|
application = FastAPI(
|
|
title=settings.PROJECT_NAME,
|
|
docs_url=docs_url,
|
|
redoc_url=redoc_url
|
|
)
|
|
|
|
|
|
# Mount Static Files
|
|
application.mount("/static", StaticFiles(directory="app/static"), name="static")
|
|
|
|
# Set up CORS
|
|
application.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
# Set up Rate Limiter
|
|
application.state.limiter = limiter
|
|
application.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_handler)
|
|
|
|
# Include routes
|
|
application.include_router(api_router, prefix="/api/v1")
|
|
application.include_router(auth.router, prefix="/auth", tags=["auth"])
|
|
application.include_router(admin_backend.router, prefix="/internal/admin", tags=["internal-admin"])
|
|
|
|
return application
|
|
|
|
app = create_application()
|
|
|
|
from fastapi.responses import FileResponse
|
|
import os
|
|
|
|
@app.get("/admin")
|
|
async def admin_panel():
|
|
return FileResponse("app/static/admin.html")
|
|
|
|
@app.get("/")
|
|
async def root():
|
|
return FileResponse("app/static/index.html")
|
|
|