55ba9b62d6
- Use in-memory SQLite for tests to prevent conflicts - Add try/finally for robust test cleanup - Make database URL configurable via env var - Make CORS origins configurable via env var - Make SQL echo configurable via env var
38 lines
1004 B
Python
38 lines
1004 B
Python
import os
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from contextlib import asynccontextmanager
|
|
from app.database import engine, Base
|
|
from app.routers import sources, jobs, executions, backups, settings, dashboard
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
async with engine.begin() as conn:
|
|
await conn.run_sync(Base.metadata.create_all)
|
|
yield
|
|
|
|
app = FastAPI(
|
|
title="Backup Tool API",
|
|
version="0.1.0",
|
|
lifespan=lifespan
|
|
)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=os.environ.get("CORS_ORIGINS", "http://localhost:3000").split(","),
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
app.include_router(sources.router)
|
|
app.include_router(jobs.router)
|
|
app.include_router(executions.router)
|
|
app.include_router(backups.router)
|
|
app.include_router(settings.router)
|
|
app.include_router(dashboard.router)
|
|
|
|
@app.get("/api/health")
|
|
async def health_check():
|
|
return {"status": "healthy"}
|