Initial commit: RSS platform phase 1 skeleton with code review fixes
Features: - FastAPI + SQLAlchemy 2.0 async + PostgreSQL/pgvector + Redis backend - Vue 3 + TypeScript + Element Plus frontend - JWT auth with access/refresh tokens and revocation - Admin/member RBAC - RSS feed CRUD and article listing - Settings management with Fernet encryption for sensitive values - Redis distributed lock service - Alembic initial migration - Docker Compose development environment Fixes from code review: - Fix DB session leak in dependency injection - Restrict registration to admin only - Add default admin password warning - Implement JWT refresh tokens and jti blacklist - Strengthen password policy - Use func.count for pagination totals - Replace NullPool with AsyncAdaptedQueuePool - Remove init_db from lifespan to enforce alembic migrations - Add request_id middleware and logging filter - Fix vite.config.ts env loading - Add frontend token refresh interceptor - Add Vue error handler Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
"""Health check router."""
|
||||
from fastapi import APIRouter, Depends, Request
|
||||
from sqlalchemy import text
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.api.deps import get_current_admin, get_db
|
||||
from app.core.redis import check_redis_health
|
||||
|
||||
router = APIRouter(prefix="/health", tags=["health"])
|
||||
|
||||
|
||||
@router.get("")
|
||||
async def health_check(request: Request, db: AsyncSession = Depends(get_db)):
|
||||
"""Basic health check."""
|
||||
db_ok = False
|
||||
try:
|
||||
await db.execute(text("SELECT 1"))
|
||||
db_ok = True
|
||||
except Exception:
|
||||
db_ok = False
|
||||
|
||||
redis_ok = await check_redis_health()
|
||||
|
||||
status_code = "ok" if db_ok and redis_ok else "degraded"
|
||||
|
||||
response = {
|
||||
"status": status_code,
|
||||
"service": "rss-platform",
|
||||
"db": "ok" if db_ok else "error",
|
||||
"redis": "ok" if redis_ok else "error",
|
||||
}
|
||||
warnings = getattr(request.app.state, "startup_warnings", None)
|
||||
if warnings:
|
||||
response["warnings"] = warnings
|
||||
return response
|
||||
|
||||
|
||||
@router.get("/db", dependencies=[Depends(get_current_admin)])
|
||||
async def db_health(db: AsyncSession = Depends(get_db)):
|
||||
"""Database health check."""
|
||||
try:
|
||||
await db.execute(text("SELECT 1"))
|
||||
return {"status": "ok", "component": "database"}
|
||||
except Exception as exc:
|
||||
return {"status": "error", "component": "database", "detail": str(exc)}
|
||||
|
||||
|
||||
@router.get("/redis", dependencies=[Depends(get_current_admin)])
|
||||
async def redis_health():
|
||||
"""Redis health check."""
|
||||
ok = await check_redis_health()
|
||||
return {"status": "ok" if ok else "error", "component": "redis"}
|
||||
Reference in New Issue
Block a user