Some checks failed
Deploy Development / deploy (push) Failing after 36s
Test Suite / pytest-backend (push) Failing after 0s
Test Suite / k6 /api/health Baseline (push) Has been skipped
Test Suite / playwright-smoke (push) Has been skipped
Test Suite / lint-backend (push) Successful in 2s
Test Suite / compose-smoke (push) Has been skipped
Co-authored-by: Cursor <cursoragent@cursor.com>
87 lines
2.0 KiB
Python
87 lines
2.0 KiB
Python
"""Jinkendo Kairo — FastAPI application entry point."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import sys
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from db import check_db
|
|
from version import APP_NAME, APP_VERSION, DB_SCHEMA_VERSION
|
|
|
|
if os.getenv("SKIP_DB_MIGRATE", "").strip().lower() in ("1", "true", "yes"):
|
|
print("[SKIP_DB_MIGRATE] Migrationen übersprungen")
|
|
else:
|
|
import run_migrations
|
|
|
|
exit_code = run_migrations.main()
|
|
if exit_code != 0:
|
|
print(f"[FAIL] Migrationen fehlgeschlagen (Exit {exit_code})")
|
|
sys.exit(exit_code)
|
|
|
|
if os.getenv("SKIP_SEEDS", "").strip().lower() not in ("1", "true", "yes"):
|
|
import run_seeds
|
|
|
|
exit_code = run_seeds.main()
|
|
if exit_code != 0:
|
|
print(f"[FAIL] Seeds fehlgeschlagen (Exit {exit_code})")
|
|
sys.exit(exit_code)
|
|
else:
|
|
print("[SKIP_SEEDS] Data-Seeds übersprungen")
|
|
|
|
allowed_origins = [
|
|
origin.strip()
|
|
for origin in os.getenv("ALLOWED_ORIGINS", "http://localhost:3097").split(",")
|
|
if origin.strip()
|
|
]
|
|
|
|
app = FastAPI(
|
|
title="Jinkendo Kairo",
|
|
version=APP_VERSION,
|
|
docs_url="/api/docs" if os.getenv("ENVIRONMENT", "development") != "production" else None,
|
|
redoc_url=None,
|
|
)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=allowed_origins,
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
from routers import auth, me # noqa: E402
|
|
|
|
app.include_router(auth.router)
|
|
app.include_router(me.router)
|
|
|
|
|
|
@app.get("/api/health")
|
|
def api_health():
|
|
db_status = "ok"
|
|
try:
|
|
if not check_db():
|
|
db_status = "error"
|
|
except Exception:
|
|
db_status = "error"
|
|
|
|
status = "ok" if db_status == "ok" else "degraded"
|
|
return {
|
|
"status": status,
|
|
"app": APP_NAME,
|
|
"db": db_status,
|
|
"version": APP_VERSION,
|
|
"schema": DB_SCHEMA_VERSION,
|
|
}
|
|
|
|
|
|
@app.get("/api/version")
|
|
def api_version():
|
|
return {
|
|
"app": APP_NAME,
|
|
"version": APP_VERSION,
|
|
"schema": DB_SCHEMA_VERSION,
|
|
}
|