30 lines
692 B
Python
30 lines
692 B
Python
from contextlib import asynccontextmanager
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from config import STORAGE_DIR
|
|
from database import init_db
|
|
from routes import router
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
(STORAGE_DIR / "html").mkdir(parents=True, exist_ok=True)
|
|
(STORAGE_DIR / "pdf").mkdir(parents=True, exist_ok=True)
|
|
(STORAGE_DIR / "preview").mkdir(parents=True, exist_ok=True)
|
|
await init_db()
|
|
yield
|
|
|
|
|
|
app = FastAPI(title="Guides Generator", lifespan=lifespan)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
app.include_router(router)
|