45 lines
1.2 KiB
Python
Executable File
45 lines
1.2 KiB
Python
Executable File
from contextlib import asynccontextmanager
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from sqlalchemy import text
|
|
import os
|
|
from app.api.v1.api import api_router
|
|
from app.api.v2.auth import router as auth_v2_router
|
|
from app.models import Base
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
from app.db.session import engine
|
|
async with engine.begin() as conn:
|
|
await conn.execute(text("CREATE SCHEMA IF NOT EXISTS data"))
|
|
await conn.run_sync(Base.metadata.create_all)
|
|
yield
|
|
await engine.dispose()
|
|
|
|
app = FastAPI(
|
|
title="Traffic Ecosystem SuperApp 2.0",
|
|
version="2.0.0",
|
|
openapi_url="/api/v2/openapi.json",
|
|
lifespan=lifespan
|
|
)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=[
|
|
"http://192.168.100.43:3000", # A szerver címe a böngészőben
|
|
"http://localhost:3000", # Helyi teszteléshez
|
|
],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
|
|
# ÚTVONALAK INTEGRÁCIÓJA
|
|
app.include_router(api_router, prefix="/api/v1")
|
|
app.include_router(auth_v2_router, prefix="/api/v2/auth")
|
|
|
|
@app.get("/", tags=["health"])
|
|
async def root():
|
|
return {"status": "online", "version": "2.0.0", "docs": "/docs"}
|
|
|