48 lines
1.3 KiB
Python
48 lines
1.3 KiB
Python
|
|
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"}
|