diff --git a/backend/app/main.py b/backend/app/main.py new file mode 100644 index 0000000..efed8a2 --- /dev/null +++ b/backend/app/main.py @@ -0,0 +1,48 @@ +from fastapi import FastAPI +from fastapi.middleware.cors import CORSMiddleware + +from app.config import get_settings +from app.database import engine, Base +from app.routers import auth, users, workspaces, tables, records, views + +settings = get_settings() + +# Create FastAPI app +app = FastAPI( + title=settings.APP_NAME, + version=settings.APP_VERSION, + debug=settings.DEBUG, +) + +# CORS middleware +app.add_middleware( + CORSMiddleware, + allow_origins=settings.CORS_ORIGINS, + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"], +) + +# Include routers +app.include_router(auth.router, prefix="/api/v1", tags=["auth"]) +app.include_router(users.router, prefix="/api/v1", tags=["users"]) +app.include_router(workspaces.router, prefix="/api/v1", tags=["workspaces"]) +app.include_router(tables.router, prefix="/api/v1", tags=["tables"]) +app.include_router(records.router, prefix="/api/v1", tags=["records"]) +app.include_router(views.router, prefix="/api/v1", tags=["views"]) + + +@app.on_event("startup") +async def startup(): + """Create tables on startup.""" + Base.metadata.create_all(bind=engine) + + +@app.get("/") +def root(): + return {"message": "FreeTable API", "version": settings.APP_VERSION} + + +@app.get("/health") +def health(): + return {"status": "healthy"} \ No newline at end of file