
- Set up FastAPI project structure with main.py and requirements.txt - Create User model with SQLAlchemy and SQLite database - Implement JWT token-based authentication system - Add password hashing with bcrypt - Create auth endpoints: register, login, and protected /me route - Set up Alembic for database migrations - Add health check endpoint with database status - Configure CORS to allow all origins - Update README with setup instructions and environment variables
19 lines
526 B
Python
19 lines
526 B
Python
from fastapi import APIRouter, Depends
|
|
from sqlalchemy.orm import Session
|
|
from app.db.session import get_db
|
|
|
|
router = APIRouter()
|
|
|
|
@router.get("/health")
|
|
def health_check(db: Session = Depends(get_db)):
|
|
try:
|
|
db.execute("SELECT 1")
|
|
database_status = "healthy"
|
|
except Exception:
|
|
database_status = "unhealthy"
|
|
|
|
return {
|
|
"status": "healthy" if database_status == "healthy" else "unhealthy",
|
|
"database": database_status,
|
|
"service": "User Authentication Service"
|
|
} |