- Add init_wizard.py: fetch config from AbstractWizard on startup - Create admin user if not exists (from wizard config) - Create default project if configured - Graceful fallback when wizard is unavailable
60 lines
1.8 KiB
Python
60 lines
1.8 KiB
Python
"""HarborForge API — Agent/人类协同任务管理平台"""
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
app = FastAPI(
|
|
title="HarborForge API",
|
|
description="Agent/人类协同任务管理平台 API",
|
|
version="0.2.0"
|
|
)
|
|
|
|
# CORS
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
# Health & version (kept at top level)
|
|
@app.get("/health", tags=["System"])
|
|
def health_check():
|
|
return {"status": "healthy"}
|
|
|
|
@app.get("/version", tags=["System"])
|
|
def version():
|
|
return {"name": "HarborForge", "version": "0.2.0", "description": "Agent/人类协同任务管理平台"}
|
|
|
|
# Register routers
|
|
from app.api.routers.auth import router as auth_router
|
|
from app.api.routers.issues import router as issues_router
|
|
from app.api.routers.projects import router as projects_router
|
|
from app.api.routers.users import router as users_router
|
|
from app.api.routers.comments import router as comments_router
|
|
from app.api.routers.webhooks import router as webhooks_router
|
|
from app.api.routers.misc import router as misc_router
|
|
|
|
app.include_router(auth_router)
|
|
app.include_router(issues_router)
|
|
app.include_router(projects_router)
|
|
app.include_router(users_router)
|
|
app.include_router(comments_router)
|
|
app.include_router(webhooks_router)
|
|
app.include_router(misc_router)
|
|
|
|
# Run database migration on startup
|
|
@app.on_event("startup")
|
|
def startup():
|
|
from app.core.config import Base, engine, SessionLocal
|
|
from app.models import webhook, apikey, activity, milestone, notification, worklog
|
|
Base.metadata.create_all(bind=engine)
|
|
|
|
# Initialize from AbstractWizard (admin user, default project, etc.)
|
|
from app.init_wizard import run_init
|
|
db = SessionLocal()
|
|
try:
|
|
run_init(db)
|
|
finally:
|
|
db.close()
|