Files
instagram-clone/app/main.py

52 lines
1.1 KiB
Python

"""FastAPI application entry point."""
from contextlib import asynccontextmanager
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app.core.config import settings
from app.db.database import engine, Base
from app.routers.auth import router as auth_router
@asynccontextmanager
async def lifespan(app: FastAPI):
"""Application lifespan manager for startup/shutdown events."""
# Startup: Create database tables
Base.metadata.create_all(bind=engine)
yield
# Shutdown: cleanup if needed
# Create FastAPI app
app = FastAPI(
title=settings.APP_NAME,
version=settings.APP_VERSION,
debug=settings.DEBUG,
lifespan=lifespan,
)
# CORS middleware
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Include routers
app.include_router(auth_router)
@app.get("/")
async def root():
"""Root endpoint."""
return {"message": f"Welcome to {settings.APP_NAME}", "version": settings.APP_VERSION}
@app.get("/health")
async def health_check():
"""Health check endpoint."""
return {"status": "healthy"}