63 lines
1.9 KiB
Python
63 lines
1.9 KiB
Python
"""FastAPI application entry point."""
|
|
|
|
from contextlib import asynccontextmanager
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from app.config import get_settings
|
|
from app.api import designs, products, cart, checkout, orders, webhooks, health, design_generator
|
|
from app.api.admin import router as admin_router
|
|
|
|
settings = get_settings()
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
"""Application lifespan handler."""
|
|
# Startup
|
|
print(f"Starting {settings.app_name}...")
|
|
print(f"Designs path: {settings.designs_path}")
|
|
print(f"POD sandbox mode: {settings.pod_sandbox_mode}")
|
|
yield
|
|
# Shutdown
|
|
print("Shutting down...")
|
|
|
|
|
|
app = FastAPI(
|
|
title=settings.app_name,
|
|
description="E-commerce API for mycopunk merchandise",
|
|
version="0.1.0",
|
|
lifespan=lifespan,
|
|
)
|
|
|
|
# CORS middleware
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=settings.cors_origins_list,
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
# Include routers
|
|
app.include_router(health.router, prefix="/api", tags=["health"])
|
|
app.include_router(designs.router, prefix="/api/designs", tags=["designs"])
|
|
app.include_router(products.router, prefix="/api/products", tags=["products"])
|
|
app.include_router(cart.router, prefix="/api/cart", tags=["cart"])
|
|
app.include_router(checkout.router, prefix="/api/checkout", tags=["checkout"])
|
|
app.include_router(orders.router, prefix="/api/orders", tags=["orders"])
|
|
app.include_router(webhooks.router, prefix="/api/webhooks", tags=["webhooks"])
|
|
app.include_router(design_generator.router, prefix="/api/design", tags=["design-generator"])
|
|
app.include_router(admin_router, prefix="/api/admin", tags=["admin"])
|
|
|
|
|
|
@app.get("/")
|
|
async def root():
|
|
"""Root endpoint."""
|
|
return {
|
|
"name": settings.app_name,
|
|
"version": "0.1.0",
|
|
"docs": "/docs",
|
|
}
|