mirror of
https://github.com/khoaliber/LetterFeed.git
synced 2026-03-02 21:19:13 +00:00
49 lines
1.3 KiB
Python
49 lines
1.3 KiB
Python
from contextlib import asynccontextmanager
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from app.core.database import Base, engine
|
|
from app.core.logging import get_logger, setup_logging
|
|
from app.core.scheduler import scheduler, start_scheduler_with_interval
|
|
from app.routers import feeds, health, imap, newsletters
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
"""Handle application startup and shutdown events."""
|
|
setup_logging()
|
|
logger = get_logger(__name__)
|
|
from app.core.config import settings
|
|
|
|
logger.info(f"DATABASE_URL used: {settings.database_url}")
|
|
logger.info("Starting up Letterfeed backend...")
|
|
Base.metadata.create_all(bind=engine)
|
|
start_scheduler_with_interval()
|
|
yield
|
|
if scheduler.running:
|
|
logger.info("Shutting down scheduler...")
|
|
scheduler.shutdown()
|
|
logger.info("...Letterfeed backend shut down.")
|
|
|
|
|
|
app = FastAPI(lifespan=lifespan)
|
|
|
|
# CORS Middleware
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=[
|
|
"http://localhost:5173",
|
|
"http://localhost:3000",
|
|
"http://127.0.0.1:5173",
|
|
],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
app.include_router(health.router)
|
|
app.include_router(imap.router)
|
|
app.include_router(newsletters.router)
|
|
app.include_router(feeds.router)
|