Spaces:
Running
Running
File size: 2,477 Bytes
30a8511 238042d 30a8511 d9e966d 1f28e6a 30a8511 f8306eb 30a8511 1f28e6a 30a8511 d9e966d 238042d 30a8511 f8306eb 30a8511 f8306eb 30a8511 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | import logging
import os
from contextlib import asynccontextmanager
import uvicorn
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from api.auth import router as auth_router
from api.enhance import router as enhance_router
from api.generate import router as generate_router, shutdown_executor
from api.integrations import router as integrations_router
from api.intake import router as intake_router
from api.oncall import router as oncall_router
from api.projects import router as projects_router
from api.admin import router as admin_router
from api.uxmaster import router as uxmaster_router
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(name)s: %(message)s")
logger = logging.getLogger(__name__)
@asynccontextmanager
async def lifespan(app: FastAPI):
try:
from db.database import create_tables
create_tables()
logger.info("DB tables ensured")
except Exception as exc: # noqa: BLE001 ponytail: DB hiccup must not stop boot
logger.error("create_tables failed (non-fatal): %s", exc)
yield
shutdown_executor()
app = FastAPI(title="CodyBuddy Studio API", version="0.1.0", lifespan=lifespan)
# ponytail: strip each origin so "a, b" (stray spaces) doesn't break the CORS match.
_origins = [o.strip() for o in os.environ.get("ALLOWED_ORIGINS", "http://localhost:3000").split(",") if o.strip()]
app.add_middleware(
CORSMiddleware,
allow_origins=_origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
app.include_router(auth_router, prefix="/api")
app.include_router(generate_router, prefix="/api")
app.include_router(enhance_router, prefix="/api")
app.include_router(uxmaster_router, prefix="/api")
app.include_router(oncall_router, prefix="/api")
app.include_router(intake_router, prefix="/api")
app.include_router(projects_router, prefix="/api")
app.include_router(admin_router, prefix="/api")
app.include_router(integrations_router, prefix="/api")
@app.get("/api/health", tags=["health"])
@app.get("/healthz", tags=["health"])
@app.get("/ping", tags=["health"])
@app.get("/", tags=["health"])
def health() -> dict:
# Lightweight, DB-free — safe for an uptime pinger to hit frequently to keep the
# HF Space warm (free Spaces sleep after ~48h idle).
return {"status": "ok", "service": "AppSmith API"}
if __name__ == "__main__":
uvicorn.run("api.main:app", host="0.0.0.0", port=8000, reload=False)
|