76 lines
2.0 KiB
Python
76 lines
2.0 KiB
Python
"""JIRA AI Fixer - Enterprise Issue Analysis Platform."""
|
|
from contextlib import asynccontextmanager
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from fastapi.staticfiles import StaticFiles
|
|
from fastapi.responses import FileResponse
|
|
import os
|
|
|
|
from app.core.config import settings
|
|
from app.core.database import init_db
|
|
from app.api import api_router
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
# Startup
|
|
await init_db()
|
|
yield
|
|
# Shutdown
|
|
|
|
app = FastAPI(
|
|
title=settings.APP_NAME,
|
|
version=settings.APP_VERSION,
|
|
description="Enterprise AI-powered issue analysis and automated fix generation",
|
|
docs_url="/api/docs",
|
|
redoc_url="/api/redoc",
|
|
openapi_url="/api/openapi.json",
|
|
lifespan=lifespan
|
|
)
|
|
|
|
# CORS
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
# API routes
|
|
app.include_router(api_router, prefix="/api")
|
|
|
|
# Health check
|
|
@app.get("/api/health")
|
|
async def health():
|
|
return {
|
|
"status": "healthy",
|
|
"service": "jira-ai-fixer",
|
|
"version": settings.APP_VERSION
|
|
}
|
|
|
|
# Serve static frontend (will be mounted if exists)
|
|
FRONTEND_DIR = "/app/frontend"
|
|
if os.path.exists(FRONTEND_DIR):
|
|
app.mount("/assets", StaticFiles(directory=f"{FRONTEND_DIR}/assets"), name="assets")
|
|
|
|
@app.get("/")
|
|
async def serve_frontend():
|
|
return FileResponse(f"{FRONTEND_DIR}/index.html")
|
|
|
|
@app.get("/{path:path}")
|
|
async def serve_spa(path: str):
|
|
file_path = f"{FRONTEND_DIR}/{path}"
|
|
if os.path.exists(file_path) and os.path.isfile(file_path):
|
|
return FileResponse(file_path)
|
|
return FileResponse(f"{FRONTEND_DIR}/index.html")
|
|
else:
|
|
# Fallback: serve basic info page
|
|
@app.get("/")
|
|
async def root():
|
|
return {
|
|
"service": settings.APP_NAME,
|
|
"version": settings.APP_VERSION,
|
|
"docs": "/api/docs",
|
|
"health": "/api/health"
|
|
}
|