# Auto-generated by create-backlist v6.0
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
import uvicorn
import os

# Import generated routers
<% for (const controller of controllers) { %>
from app.routes import <%= controller.toLowerCase() %>_routes
<% } %>

# Create FastAPI app instance
app = FastAPI(title="<%= projectName %>")

# CORS (Cross-Origin Resource Sharing) Middleware
# This allows your frontend to communicate with this backend
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],  # In production, specify your frontend's origin
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

# Root endpoint
@app.get("/")
def read_root():
    return {"message": "Welcome to the FastAPI backend generated by create-backlist!"}

# Include generated routers
<% for (const controller of controllers) { %>
app.include_router(<%= controller.toLowerCase() %>_routes.router, prefix="/api")
<% } %>


if __name__ == "__main__":
    port = int(os.getenv("PORT", 8000))
    uvicorn.run(app, host="0.0.0.0", port=port)