-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
93 lines (75 loc) · 2.22 KB
/
main.py
File metadata and controls
93 lines (75 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
"""
PCGIntegrator3D FastAPI Application
Main application entry point for the PCG (Procedural Content Generation) service.
This service provides REST APIs for various PCG modules including Infinigen and others.
"""
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from contextlib import asynccontextmanager
import logging
from app.routers import infinigen
from app.core.config import settings
# 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 for startup and shutdown events.
"""
# Startup
logger.info("Starting PCGIntegrator3D service...")
logger.info(f"Environment: {settings.ENVIRONMENT}")
logger.info(f"API Version: {settings.API_VERSION}")
yield
# Shutdown
logger.info("Shutting down PCGIntegrator3D service...")
# Initialize FastAPI application
app = FastAPI(
title=settings.PROJECT_NAME,
description=settings.PROJECT_DESCRIPTION,
version=settings.API_VERSION,
lifespan=lifespan,
docs_url="/docs",
redoc_url="/redoc",
openapi_url="/openapi.json",
)
# Configure CORS
app.add_middleware(
CORSMiddleware,
allow_origins=settings.ALLOWED_ORIGINS,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Include routers
app.include_router(infinigen.router, prefix="/api/v1/infinigen", tags=["Infinigen"])
# Health check endpoint
@app.get("/health", tags=["Health"])
async def health_check():
"""
Health check endpoint to verify service status.
Returns:
dict: Service health status
"""
return {
"status": "healthy",
"service": settings.PROJECT_NAME,
"version": settings.API_VERSION,
"environment": settings.ENVIRONMENT,
}
@app.get("/", tags=["Root"])
async def root():
"""
Root endpoint providing basic service information.
Returns:
dict: Service information
"""
return {
"message": "Welcome to PCGIntegrator3D API",
"version": settings.API_VERSION,
"docs": "/docs",
"health": "/health",
}