33 lines
661 B
Python
33 lines
661 B
Python
from contextlib import asynccontextmanager
|
|
|
|
from fastapi import FastAPI
|
|
|
|
from api.proxy.router import router as proxy_router
|
|
from db.proxy import ensure_proxy_indexes
|
|
from core.mongodb import close_mongodb, init_mongodb
|
|
from core.redis import close_redis, init_redis
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(_: FastAPI):
|
|
await init_mongodb()
|
|
await init_redis()
|
|
await ensure_proxy_indexes()
|
|
try:
|
|
yield
|
|
finally:
|
|
await close_redis()
|
|
await close_mongodb()
|
|
|
|
app = FastAPI(
|
|
title="thePlugAPI",
|
|
lifespan=lifespan,
|
|
)
|
|
|
|
app.include_router(proxy_router)
|
|
|
|
|
|
@app.get("/")
|
|
async def root():
|
|
return {"Hello": "World!"}
|