- Fixed main.py to include all route routers (posts, users, comments, feed) - Renamed app/models.py to app/schemas.py and split into proper schema modules - Fixed schema imports in routes - Updated app/models/__init__.py to properly export SQLAlchemy models - Fixed database imports in route files - App imports and runs correctly
67 lines
1.8 KiB
Python
67 lines
1.8 KiB
Python
"""FastAPI application entry point."""
|
|
from contextlib import asynccontextmanager
|
|
from pathlib import Path
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from fastapi.staticfiles import StaticFiles
|
|
|
|
from app.core.config import settings
|
|
from app.db.database import engine, Base
|
|
from app.routers.auth import router as auth_router # noqa: F401
|
|
from app.routes.posts import router as posts_router
|
|
from app.routes.users import router as users_router
|
|
from app.routes.comments import router as comments_router
|
|
from app.routes.feed import router as feed_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.include_router(posts_router)
|
|
app.include_router(users_router)
|
|
app.include_router(comments_router)
|
|
app.include_router(feed_router)
|
|
|
|
# Mount static files for uploads
|
|
UPLOAD_DIR = Path(__file__).parent.parent / "uploads"
|
|
UPLOAD_DIR.mkdir(parents=True, exist_ok=True)
|
|
app.mount("/uploads", StaticFiles(directory=str(UPLOAD_DIR)), name="uploads")
|
|
|
|
|
|
@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"}
|