Files
video-service/app/main.py

82 lines
2.1 KiB
Python
Executable File

"""
Video-Service for Kurs-Booking Plugin
FastAPI Application Entry Point
"""
import logging
from contextlib import asynccontextmanager
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app import __version__
from app.api.routes import router
from app.config import get_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 handler."""
settings = get_settings()
logger.info(f"Starting Video-Service v{__version__}")
logger.info(f"Environment: {settings.environment}")
logger.info(f"Storage path: {settings.storage_path}")
logger.info(f"Redis URL: {settings.redis_url}")
yield
logger.info("Shutting down Video-Service")
# Create FastAPI app
settings = get_settings()
app = FastAPI(
title="Kurs-Booking Video-Service",
description="Video hosting and streaming service for Kurs-Booking WordPress plugin",
version=__version__,
docs_url="/docs" if settings.debug else None,
redoc_url="/redoc" if settings.debug else None,
openapi_url="/openapi.json" if settings.debug else None,
lifespan=lifespan,
)
# CORS middleware
app.add_middleware(
CORSMiddleware,
allow_origins=settings.allowed_origins_list,
allow_credentials=True,
allow_methods=["GET", "POST", "DELETE"],
allow_headers=["*"],
expose_headers=["Content-Disposition"],
)
# Include API routes
app.include_router(router, prefix="/api/v1")
# Root endpoint
@app.get("/")
async def root():
"""Root endpoint with service info."""
return {
"service": "Kurs-Booking Video-Service",
"version": __version__,
"docs": "/docs" if settings.debug else "disabled",
"health": "/api/v1/health",
}
# Health check at root level (for Docker health checks)
@app.get("/health")
async def health():
"""Simple health check for Docker."""
return {"status": "ok"}