50 lines
1.4 KiB
Python
Executable File
50 lines
1.4 KiB
Python
Executable File
import os
|
|
from contextlib import asynccontextmanager
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from sqlalchemy import text
|
|
from app.api.v1.api import api_router
|
|
from app.db.base import Base
|
|
from app.db.session import engine
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
# Séma és alap táblák ellenőrzése indításkor
|
|
async with engine.begin() as conn:
|
|
await conn.execute(text("CREATE SCHEMA IF NOT EXISTS data"))
|
|
# Base.metadata.create_all helyett javasolt az Alembic,
|
|
# de fejlesztési fázisban a run_sync biztonságos
|
|
await conn.run_sync(Base.metadata.create_all)
|
|
yield
|
|
await engine.dispose()
|
|
|
|
app = FastAPI(
|
|
title="Service Finder API",
|
|
version="1.0.0",
|
|
docs_url="/docs",
|
|
openapi_url="/api/v1/openapi.json",
|
|
lifespan=lifespan
|
|
)
|
|
|
|
# BIZTONSÁG: CORS beállítások .env-ből
|
|
# Ha nincs megadva, csak a localhost-ot engedi
|
|
origins = os.getenv("CORS_ORIGINS", "http://localhost:3000").split(",")
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=origins,
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
# ÚTVONALAK KONSZOLIDÁCIÓJA (V2 törölve, minden a V1 alatt)
|
|
app.include_router(api_router, prefix="/api/v1")
|
|
|
|
@app.get("/", tags=["health"])
|
|
async def root():
|
|
return {
|
|
"status": "online",
|
|
"version": "1.0.0",
|
|
"environment": os.getenv("ENV", "production")
|
|
} |