main.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import os
  2. from fastapi import FastAPI
  3. from fastapi.middleware.cors import CORSMiddleware
  4. # Routes to be included
  5. from app.api.routes import auth
  6. from app.api.routes import investigations
  7. from app.api.routes import sketches
  8. from app.api.routes import enrichers
  9. from app.api.routes import flows
  10. from app.api.routes import events
  11. from app.api.routes import analysis
  12. from app.api.routes import chat
  13. from app.api.routes import scan
  14. from app.api.routes import keys
  15. from app.api.routes import types
  16. from app.api.routes import custom_types
  17. from app.api.routes import enricher_templates
  18. # Comma-separated list of allowed origins, e.g. "https://app.example.com,https://staging.example.com"
  19. # Falls back to localhost dev origin when unset. Never use "*" with allow_credentials=True.
  20. origins = [
  21. o.strip()
  22. for o in os.getenv("ALLOWED_ORIGINS", "http://localhost:5173").split(",")
  23. if o.strip()
  24. ]
  25. app = FastAPI(ignore_trailing_slash=True, redirect_slashes=False)
  26. app.add_middleware(
  27. CORSMiddleware,
  28. allow_origins=origins,
  29. allow_credentials=True,
  30. allow_methods=["*"],
  31. allow_headers=["*"],
  32. )
  33. @app.get("/health")
  34. async def health():
  35. """Health check endpoint for Docker healthcheck"""
  36. return {"status": "ok"}
  37. app.include_router(auth.router, prefix="/api/auth", tags=["auth"])
  38. app.include_router(sketches.router, prefix="/api/sketches", tags=["sketches"])
  39. app.include_router(
  40. investigations.router, prefix="/api/investigations", tags=["investigations"]
  41. )
  42. app.include_router(enrichers.router, prefix="/api/enrichers", tags=["enrichers"])
  43. app.include_router(flows.router, prefix="/api/flows", tags=["flows"])
  44. app.include_router(events.router, prefix="/api/events", tags=["events"])
  45. app.include_router(analysis.router, prefix="/api/analyses", tags=["analyses"])
  46. app.include_router(chat.router, prefix="/api/chats", tags=["chats"])
  47. app.include_router(scan.router, prefix="/api/scans", tags=["scans"])
  48. app.include_router(keys.router, prefix="/api/keys", tags=["keys"])
  49. app.include_router(types.router, prefix="/api/types", tags=["types"])
  50. app.include_router(custom_types.router, prefix="/api/custom-types", tags=["custom-types"])
  51. app.include_router(enricher_templates.router, prefix="/api/enrichers/templates", tags=["enricher-templates"])