
- Set up project structure and FastAPI application - Create database models for users, products, and inventory - Configure SQLAlchemy and Alembic for database management - Implement JWT authentication - Create API endpoints for user, product, and inventory management - Add admin-only routes and authorization middleware - Add health check endpoint - Update README with documentation - Lint and fix code issues
64 lines
1.5 KiB
Python
64 lines
1.5 KiB
Python
|
|
import uvicorn
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from fastapi.openapi.utils import get_openapi
|
|
|
|
from app.api.api import api_router
|
|
from app.core.config import settings
|
|
|
|
# Create the app instance
|
|
app = FastAPI(
|
|
title=settings.PROJECT_NAME,
|
|
description="Authentication and Inventory API for ecommerce",
|
|
version="0.1.0",
|
|
openapi_url="/openapi.json",
|
|
)
|
|
|
|
# Configure CORS
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=[origin for origin in settings.BACKEND_CORS_ORIGINS],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
# Root endpoint
|
|
@app.get("/")
|
|
async def root():
|
|
"""Root endpoint returns basic API information."""
|
|
return {
|
|
"title": settings.PROJECT_NAME,
|
|
"documentation": "/docs",
|
|
"health_check": "/health"
|
|
}
|
|
|
|
# Health check endpoint
|
|
@app.get("/health")
|
|
async def health():
|
|
"""Health check endpoint."""
|
|
return {"status": "ok"}
|
|
|
|
# Custom OpenAPI schema
|
|
def custom_openapi():
|
|
if app.openapi_schema:
|
|
return app.openapi_schema
|
|
|
|
openapi_schema = get_openapi(
|
|
title=settings.PROJECT_NAME,
|
|
version="0.1.0",
|
|
description="Authentication and Inventory API for ecommerce",
|
|
routes=app.routes,
|
|
)
|
|
|
|
app.openapi_schema = openapi_schema
|
|
return app.openapi_schema
|
|
|
|
app.openapi = custom_openapi
|
|
|
|
# Include API router
|
|
app.include_router(api_router)
|
|
|
|
if __name__ == "__main__":
|
|
uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True) |