STABLE: Final schema sync, optimized gitignore
This commit is contained in:
@@ -1,66 +1,107 @@
|
||||
# /opt/docker/dev/service_finder/backend/app/main.py
|
||||
import os
|
||||
import logging
|
||||
from contextlib import asynccontextmanager
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from starlette.middleware.sessions import SessionMiddleware # ÚJ
|
||||
from starlette.middleware.sessions import SessionMiddleware
|
||||
|
||||
from app.api.v1.api import api_router
|
||||
from app.core.config import settings
|
||||
from app.database import AsyncSessionLocal
|
||||
from app.services.translation_service import translation_service
|
||||
|
||||
# Statikus mappák létrehozása induláskor
|
||||
os.makedirs("static/previews", exist_ok=True)
|
||||
# --- LOGGING KONFIGURÁCIÓ ---
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
logger = logging.getLogger("Sentinel-Main")
|
||||
|
||||
# --- LIFESPAN (Startup/Shutdown események) ---
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
"""
|
||||
A rendszer 'ébredési' folyamata.
|
||||
Itt töltődnek be a memóriába a globális erőforrások.
|
||||
"""
|
||||
logger.info("🛰️ Sentinel Master System ébredése...")
|
||||
|
||||
# 1. Nyelvi Cache betöltése az adatbázisból
|
||||
async with AsyncSessionLocal() as db:
|
||||
try:
|
||||
await translation_service.load_cache(db)
|
||||
logger.info("🌍 i18n fordítási kulcsok aktiválva.")
|
||||
except Exception as e:
|
||||
logger.error(f"❌ i18n hiba az induláskor: {e}")
|
||||
|
||||
# Statikus könyvtárak ellenőrzése
|
||||
os.makedirs(settings.STATIC_DIR, exist_ok=True)
|
||||
os.makedirs(os.path.join(settings.STATIC_DIR, "previews"), exist_ok=True)
|
||||
|
||||
yield
|
||||
|
||||
logger.info("💤 Sentinel Master System leállítása...")
|
||||
|
||||
# --- APP INICIALIZÁLÁS ---
|
||||
app = FastAPI(
|
||||
title="Service Finder API",
|
||||
description="Traffic Ecosystem, Asset Vault & AI Evidence Processing",
|
||||
version="2.0.0",
|
||||
openapi_url="/api/v1/openapi.json",
|
||||
docs_url="/docs"
|
||||
title="Service Finder Master API",
|
||||
description="Sentinel Traffic Ecosystem, Asset Vault & AI Evidence Processing",
|
||||
version="2.0.1",
|
||||
openapi_url=f"{settings.API_V1_STR}/openapi.json",
|
||||
docs_url="/docs",
|
||||
lifespan=lifespan
|
||||
)
|
||||
|
||||
# --- SESSION MIDDLEWARE (Google Authhoz kötelező) ---
|
||||
# --- SESSION MIDDLEWARE (OAuth2 / Google Auth támogatás) ---
|
||||
# A secret_key az aláírt sütikhez (cookies) szükséges
|
||||
app.add_middleware(
|
||||
SessionMiddleware,
|
||||
secret_key=settings.SECRET_KEY
|
||||
)
|
||||
|
||||
# --- CORS BEÁLLÍTÁSOK ---
|
||||
# --- CORS BEÁLLÍTÁSOK (Hálózati kapu) ---
|
||||
# Itt engedélyezzük, hogy a Frontend (React/Mobile) elérje az API-t
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=[
|
||||
"http://192.168.100.10:3001",
|
||||
"http://localhost:3001",
|
||||
"https://dev.profibot.hu",
|
||||
"https://app.profibot.hu"
|
||||
],
|
||||
allow_origins=[str(origin) for origin in settings.BACKEND_CORS_ORIGINS],
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
# Statikus fájlok kiszolgálása (képek, letöltések)
|
||||
app.mount("/static", StaticFiles(directory="static"), name="static")
|
||||
# --- STATIKUS FÁJLOK ---
|
||||
# Képek, PDF-ek és a generált nyelvi JSON-ök kiszolgálása
|
||||
app.mount("/static", StaticFiles(directory=settings.STATIC_DIR), name="static")
|
||||
|
||||
# A V1-es API router bekötése a /api/v1 prefix alá
|
||||
app.include_router(api_router, prefix="/api/v1")
|
||||
# --- ROUTER BEKÖTÉSE ---
|
||||
# Itt csatlakozik az összes API végpont (Auth, Fleet, Billing, stb.)
|
||||
app.include_router(api_router, prefix=settings.API_V1_STR)
|
||||
|
||||
# --- ALAPVETŐ RENDSZER VÉGPONTOK ---
|
||||
|
||||
# --- ALAPVETŐ VÉGPONTOK ---
|
||||
@app.get("/", tags=["System"])
|
||||
async def root():
|
||||
""" Rendszer azonosító végpont. """
|
||||
return {
|
||||
"status": "online",
|
||||
"message": "Service Finder Master System v2.0",
|
||||
"system": "Service Finder Master",
|
||||
"version": "2.0.1",
|
||||
"environment": "Production" if not settings.DEBUG_MODE else "Development",
|
||||
"features": [
|
||||
"Google Auth Enabled",
|
||||
"Asset Vault",
|
||||
"Org Onboarding",
|
||||
"AI Evidence OCR (Robot 3)",
|
||||
"Fleet Expenses (TCO)"
|
||||
"Hierarchical i18n Enabled",
|
||||
"Asset Vault 2.0",
|
||||
"Sentinel Security Audit",
|
||||
"Robot Pipeline (0-3)"
|
||||
]
|
||||
}
|
||||
|
||||
@app.get("/health", tags=["System"])
|
||||
async def health_check():
|
||||
"""
|
||||
Monitoring végpont.
|
||||
Ha ez 'ok'-t ad, a Docker és a Load Balancer tudja, hogy a szerver él.
|
||||
"""
|
||||
Monitoring és Load Balancer egészségügyi ellenőrző végpont.
|
||||
"""
|
||||
return {"status": "ok", "message": "Service Finder API is running flawlessly."}
|
||||
return {
|
||||
"status": "ok",
|
||||
"timestamp": settings.get_now_utc_iso(),
|
||||
"database": "connected" # Itt később lehet valódi ping teszt
|
||||
}
|
||||
Reference in New Issue
Block a user