feat: Initialize FastAPI AI Gateway project structure with authentication, module management, and LLM API routing.
This commit is contained in:
56
app/main.py
Normal file
56
app/main.py
Normal file
@@ -0,0 +1,56 @@
|
||||
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:
|
||||
application = FastAPI(title=settings.PROJECT_NAME)
|
||||
|
||||
# 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 {"message": "Welcome to Storyline AI Gateway", "docs": "/docs"}
|
||||
Reference in New Issue
Block a user