Files
xdl/backend/app/main.py

47 lines
1.0 KiB
Python

"""XDL - Twitter/X Video Downloader API."""
import asyncio
import os
from contextlib import asynccontextmanager
from dotenv import load_dotenv
load_dotenv()
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app.database import init_db
from app.routes import auth, parse, download, admin
from app.services.cleanup import cleanup_loop
@asynccontextmanager
async def lifespan(app: FastAPI):
await init_db()
task = asyncio.create_task(cleanup_loop())
yield
task.cancel()
try:
await task
except asyncio.CancelledError:
pass
app = FastAPI(title="XDL - Video Downloader", version="1.0.0", lifespan=lifespan)
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
app.include_router(auth.router)
app.include_router(parse.router)
app.include_router(download.router)
app.include_router(admin.router)
@app.get("/api/health")
async def health():
return {"status": "ok"}