Python/FastAPI backend with PostgreSQL for collecting Reddit data via public .json endpoints. React/Vite dashboard for analytics. Docker Compose setup with API and worker services connecting to shared PostgreSQL. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
from contextlib import asynccontextmanager
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.staticfiles import StaticFiles
|
|
from fastapi.responses import FileResponse
|
|
|
|
from backend.database import engine
|
|
from backend.routers import health, subreddits, posts, comments, authors, analytics, digests, summaries
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
yield
|
|
await engine.dispose()
|
|
|
|
|
|
app = FastAPI(title="Reddit Monitor", lifespan=lifespan)
|
|
|
|
# API routes
|
|
app.include_router(health.router, prefix="/api/v1")
|
|
app.include_router(subreddits.router, prefix="/api/v1")
|
|
app.include_router(posts.router, prefix="/api/v1")
|
|
app.include_router(comments.router, prefix="/api/v1")
|
|
app.include_router(authors.router, prefix="/api/v1")
|
|
app.include_router(analytics.router, prefix="/api/v1")
|
|
app.include_router(digests.router, prefix="/api/v1")
|
|
app.include_router(summaries.router, prefix="/api/v1")
|
|
|
|
|
|
# SPA static file serving (only when frontend is built)
|
|
import os
|
|
|
|
static_dir = os.path.join(os.path.dirname(__file__), "..", "static")
|
|
if os.path.isdir(static_dir):
|
|
app.mount("/assets", StaticFiles(directory=os.path.join(static_dir, "assets")), name="assets")
|
|
|
|
@app.get("/{full_path:path}")
|
|
async def serve_spa(full_path: str):
|
|
return FileResponse(os.path.join(static_dir, "index.html"))
|