diff --git a/backend/lcfs/web/api/monitoring/views.py b/backend/lcfs/web/api/monitoring/views.py index 1b36caf02..c599ef0b1 100644 --- a/backend/lcfs/web/api/monitoring/views.py +++ b/backend/lcfs/web/api/monitoring/views.py @@ -4,9 +4,10 @@ @router.get("/health") -def health_check() -> None: +def health_check() -> str: """ Checks the health of a project. It returns 200 if the project is healthy. """ + return "healthy" diff --git a/backend/lcfs/web/application.py b/backend/lcfs/web/application.py index 6d31484d0..e7117a105 100644 --- a/backend/lcfs/web/application.py +++ b/backend/lcfs/web/application.py @@ -1,30 +1,26 @@ -from importlib import metadata -import structlog import logging +import uuid -import os -import debugpy +import structlog from fastapi import FastAPI, HTTPException from fastapi.exceptions import RequestValidationError -from fastapi.responses import UJSONResponse from fastapi.middleware.cors import CORSMiddleware +from fastapi.responses import UJSONResponse from prometheus_fastapi_instrumentator import Instrumentator -from starlette.middleware.authentication import AuthenticationMiddleware from starlette.authentication import ( AuthenticationBackend, AuthCredentials, UnauthenticatedUser, ) +from starlette.middleware.authentication import AuthenticationMiddleware from starlette.middleware.base import BaseHTTPMiddleware from starlette.requests import Request from starlette.responses import JSONResponse -import uuid -import contextvars -from lcfs.settings import settings from lcfs.logging_config import setup_logging, correlation_id_var -from lcfs.web.api.router import api_router from lcfs.services.keycloak.authentication import UserAuthentication +from lcfs.settings import settings +from lcfs.web.api.router import api_router from lcfs.web.exception.exception_handler import validation_exception_handler from lcfs.web.lifetime import register_shutdown_event, register_startup_event @@ -67,6 +63,9 @@ async def authenticate(self, request): if request.scope["method"] == "OPTIONS": return AuthCredentials([]), UnauthenticatedUser() + if request.url.path == "/api/health": # Skip for health check + return AuthCredentials([]), UnauthenticatedUser() + # Lazily retrieve Redis, session, and settings from app state redis_client = self.app.state.redis_client session_factory = self.app.state.db_session_factory