Mirrored from https://github.com/Camo67/OCIU-npo.git
Synced Nov 21, 03:37 UTC
fix/ociu-remove-placeholder-content
| 1 | import os |
| 2 | from fastapi import FastAPI, Depends, Request |
| 3 | from fastapi.responses import StreamingResponse |
| 4 | from fastapi.middleware.cors import CORSMiddleware |
| 5 | from dotenv import load_dotenv |
| 6 | import asyncio |
| 7 | from typing import List, AsyncGenerator |
| 8 | from backend.api.endpoints import api_router |
| 9 | from backend.api.business_suite import business_suite_router |
| 10 | from backend.api.gemini_proxy import gemini_router |
| 11 | from backend.api.billing import billing_router |
| 12 | from backend.middleware.subscription import subscription_middleware |
| 13 | from backend.services.sse import sse_manager |
| 14 | |
| 15 | load_dotenv() |
| 16 | |
| 17 | app = FastAPI(title="CamoFlow OS API") |
| 18 | app.include_router(api_router, prefix="/api") |
| 19 | app.include_router(business_suite_router, prefix="/business-suite") |
| 20 | app.include_router(gemini_router, prefix="/api/gemini") |
| 21 | app.include_router(billing_router, prefix="/api/billing") |
| 22 | |
| 23 | app.middleware("http")(subscription_middleware) |
| 24 | |
| 25 | # Get allowed origins from environment variable, default to localhost for development |
| 26 | allowed_origins = os.getenv("ALLOWED_ORIGINS", "http://localhost:5173,http://localhost:3000").split(",") |
| 27 | |
| 28 | app.add_middleware( |
| 29 | CORSMiddleware, |
| 30 | allow_origins=allowed_origins, |
| 31 | allow_credentials=True, |
| 32 | allow_methods=["GET", "POST", "PUT", "DELETE", "OPTIONS"], |
| 33 | allow_headers=["Content-Type", "Authorization", "X-User-Id"], |
| 34 | expose_headers=["X-Request-Id"], |
| 35 | max_age=600, |
| 36 | ) |
| 37 | |
| 38 | @app.get("/") |
| 39 | async def root(): |
| 40 | return {"message": "CamoFlow OS Orchestration Layer Running"} |
| 41 | |
| 42 | @app.get("/health") |
| 43 | async def health(): |
| 44 | return {"status": "healthy"} |
| 45 | |
| 46 | @app.get("/api/events") |
| 47 | async def events(request: Request): |
| 48 | return StreamingResponse(sse_manager.subscribe(), media_type="text/event-stream") |
| 49 | |
| 50 | @app.on_event("startup") |
| 51 | async def startup_event(): |
| 52 | import threading |
| 53 | from backend.services.self_healing import start_self_heal |
| 54 | threading.Thread(target=start_self_heal, daemon=True).start() |
| 55 | |
| 56 | if __name__ == "__main__": |
| 57 | import uvicorn |
| 58 | uvicorn.run(app, host="0.0.0.0", port=8000) |