Some checks failed
Deploy to Production / deploy (push) Failing after 46s
- Remove nginx from docker-compose.prod.yml (NPM handles reverse proxy) - Add Next.js rewrites to proxy /api/* to backend (backend fully hidden) - Bind frontend to 127.0.0.1:3000 only (NPM proxies externally) - Replace hardcoded localhost:8000 in history page with api client - Make CORS origins configurable via environment variable - Restrict CORS methods to GET/POST/PUT/DELETE - Add Gitea Actions deploy workflow with secrets-based env management - Add security headers (X-Frame-Options, X-Content-Type-Options, Referrer-Policy) - Add BACKEND_URL build arg to frontend Dockerfile for standalone builds Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
82 lines
2.0 KiB
Python
82 lines
2.0 KiB
Python
"""
|
|
Galaxis-Po Backend API
|
|
"""
|
|
import logging
|
|
from contextlib import asynccontextmanager
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from app.api import (
|
|
auth_router, admin_router, portfolio_router, strategy_router,
|
|
market_router, backtest_router, snapshot_router,
|
|
)
|
|
|
|
# Configure logging
|
|
logging.basicConfig(
|
|
level=logging.INFO,
|
|
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
|
|
)
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
"""Application lifespan manager."""
|
|
# Startup
|
|
logger.info("Starting Galaxis-Po API...")
|
|
|
|
# Start scheduler (import here to avoid circular imports)
|
|
try:
|
|
from jobs.scheduler import start_scheduler
|
|
start_scheduler()
|
|
logger.info("Scheduler started")
|
|
except Exception as e:
|
|
logger.warning(f"Failed to start scheduler: {e}")
|
|
|
|
yield
|
|
|
|
# Shutdown
|
|
logger.info("Shutting down Galaxis-Po API...")
|
|
|
|
try:
|
|
from jobs.scheduler import stop_scheduler
|
|
stop_scheduler()
|
|
logger.info("Scheduler stopped")
|
|
except Exception as e:
|
|
logger.warning(f"Failed to stop scheduler: {e}")
|
|
|
|
|
|
app = FastAPI(
|
|
title="Galaxis-Po API",
|
|
description="Quant Portfolio Management API",
|
|
version="0.1.0",
|
|
lifespan=lifespan,
|
|
)
|
|
|
|
from app.core.config import get_settings
|
|
|
|
_settings = get_settings()
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=[origin.strip() for origin in _settings.cors_origins.split(",") if origin.strip()],
|
|
allow_credentials=True,
|
|
allow_methods=["GET", "POST", "PUT", "DELETE"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
# Include routers
|
|
app.include_router(auth_router)
|
|
app.include_router(admin_router)
|
|
app.include_router(portfolio_router)
|
|
app.include_router(strategy_router)
|
|
app.include_router(market_router)
|
|
app.include_router(backtest_router)
|
|
app.include_router(snapshot_router)
|
|
|
|
|
|
@app.get("/health")
|
|
async def health_check():
|
|
return {"status": "healthy"}
|