62 lines
1.4 KiB
Python
62 lines
1.4 KiB
Python
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from contextlib import asynccontextmanager
|
|
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
|
|
|
from .routers import auth, tenants, admin
|
|
from .services.trial_monitor import check_trials
|
|
from .core.config import get_settings
|
|
|
|
scheduler = AsyncIOScheduler()
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
# Start trial monitor (runs every hour)
|
|
scheduler.add_job(check_trials, "interval", hours=1, id="trial_monitor")
|
|
scheduler.start()
|
|
yield
|
|
scheduler.shutdown()
|
|
|
|
|
|
s = get_settings()
|
|
app = FastAPI(
|
|
title="Platform API",
|
|
description="Managed Data Platform — Control Plane API",
|
|
version="1.0.0",
|
|
lifespan=lifespan,
|
|
)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=[
|
|
f"https://app.{s.DOMAIN}",
|
|
f"https://data.{s.DOMAIN}",
|
|
f"https://admin.{s.DOMAIN}",
|
|
"http://localhost:3000",
|
|
"http://localhost:8080",
|
|
],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
expose_headers=["*"],
|
|
)
|
|
|
|
app.include_router(auth.router)
|
|
app.include_router(tenants.router)
|
|
app.include_router(admin.router)
|
|
|
|
|
|
@app.get("/health")
|
|
async def health():
|
|
return {"status": "ok"}
|
|
|
|
|
|
@app.get("/")
|
|
async def root():
|
|
return {
|
|
"service": "Platform API",
|
|
"docs": "/docs",
|
|
"health": "/health",
|
|
}
|