Use host ports 3006/8005 and 3096/8096 so Kansho does not collide with Bookstack on 3005 or the sister products. Co-authored-by: Cursor <cursoragent@cursor.com>
65 lines
1.7 KiB
Python
65 lines
1.7 KiB
Python
from env_loader import load_env_file
|
|
|
|
load_env_file()
|
|
|
|
import os
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from db import init_db
|
|
import data_layer_dialogue # noqa: F401
|
|
from routers import admin, auth, dialogue, generation_instructions, journal, placeholders, prompts, subscription, users
|
|
from version import APP_VERSION
|
|
|
|
|
|
def allowed_origins() -> list[str]:
|
|
origins = [
|
|
"http://localhost:5188",
|
|
"http://127.0.0.1:5188",
|
|
"https://kansho.jinkendo.de",
|
|
"https://dev.kansho.jinkendo.de",
|
|
]
|
|
extra = (os.environ.get("ALLOWED_ORIGINS") or os.environ.get("KANSHO_ALLOWED_ORIGINS") or "").strip()
|
|
if extra:
|
|
origins.extend(item.strip() for item in extra.split(",") if item.strip())
|
|
app_url = (os.environ.get("APP_URL") or "").strip().rstrip("/")
|
|
if app_url:
|
|
origins.append(app_url)
|
|
seen: list[str] = []
|
|
for item in origins:
|
|
if item not in seen:
|
|
seen.append(item)
|
|
return seen
|
|
|
|
|
|
app = FastAPI(title="Kanshō", version=APP_VERSION)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=allowed_origins(),
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
app.include_router(auth.router)
|
|
app.include_router(users.router)
|
|
app.include_router(dialogue.router)
|
|
app.include_router(journal.router)
|
|
app.include_router(prompts.router)
|
|
app.include_router(placeholders.router)
|
|
app.include_router(subscription.router)
|
|
app.include_router(admin.router)
|
|
app.include_router(generation_instructions.router)
|
|
|
|
|
|
@app.on_event("startup")
|
|
def on_startup():
|
|
init_db()
|
|
|
|
|
|
@app.get("/api/health")
|
|
def health():
|
|
return {"status": "ok", "service": "kansho", "version": APP_VERSION}
|