63 lines
1.6 KiB
Python
63 lines
1.6 KiB
Python
import logging
|
|
from pathlib import Path
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from prometheus_fastapi_instrumentator import Instrumentator
|
|
|
|
from app.api.v1.api import api_router
|
|
from app.core.config import settings
|
|
|
|
# Setup logging
|
|
logging.basicConfig(
|
|
level=logging.INFO,
|
|
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
|
|
)
|
|
logger = logging.getLogger(__name__)
|
|
|
|
app = FastAPI(
|
|
title=settings.APP_NAME,
|
|
openapi_url="/openapi.json",
|
|
docs_url="/docs",
|
|
redoc_url="/redoc",
|
|
)
|
|
|
|
# Set up CORS middleware
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"], # Allow all origins
|
|
allow_credentials=True,
|
|
allow_methods=["*"], # Allow all methods
|
|
allow_headers=["*"], # Allow all headers
|
|
)
|
|
|
|
# Add Prometheus metrics
|
|
Instrumentator().instrument(app).expose(app)
|
|
|
|
# Include API router
|
|
app.include_router(api_router, prefix=settings.API_V1_PREFIX)
|
|
|
|
|
|
@app.get("/", tags=["Root"])
|
|
async def root():
|
|
"""
|
|
Root endpoint that returns application information.
|
|
"""
|
|
return {
|
|
"name": settings.APP_NAME,
|
|
"docs": "/docs",
|
|
"health_check": f"{settings.API_V1_PREFIX}/health",
|
|
}
|
|
|
|
|
|
if __name__ == "__main__":
|
|
import uvicorn
|
|
|
|
# Ensure storage directories exist
|
|
storage_dir = Path("/app/storage")
|
|
storage_dir.mkdir(parents=True, exist_ok=True)
|
|
(storage_dir / "db").mkdir(exist_ok=True)
|
|
(storage_dir / "voice_notes").mkdir(exist_ok=True)
|
|
(storage_dir / "reports").mkdir(exist_ok=True)
|
|
|
|
uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True) |