38 lines
942 B
Python
38 lines
942 B
Python
from collections.abc import AsyncGenerator
|
|
from contextlib import asynccontextmanager
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from remodel_api import __version__
|
|
from remodel_api.db.session import init_db
|
|
from remodel_api.routers import scenarios
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI) -> AsyncGenerator[None, None]: # pragma: no cover
|
|
await init_db()
|
|
yield
|
|
|
|
|
|
app = FastAPI(
|
|
title="REmodel API",
|
|
version=__version__,
|
|
description="Hybrid RE project finance modeling — Solar + Wind + BESS",
|
|
lifespan=lifespan,
|
|
)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["http://localhost:3000"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
app.include_router(scenarios.router, prefix="/api")
|
|
|
|
|
|
@app.get("/healthz", tags=["ops"])
|
|
async def healthz() -> dict[str, str]:
|
|
return {"status": "ok", "version": __version__}
|