Skip to content

Commit 63684b0

Browse files
Merge pull request #128 from rudra3007-pro/feat/health-check-endpoint
feat: add /health endpoint for server status check
2 parents 6611f46 + a85ee01 commit 63684b0

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

routes/main_routes.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from utils.recommender import get_recommendations, validate_recommendation_inputs
99
from utils.data_loader import find_project_by_id, get_project_stats
1010
from utils.file_server import read_starter_code, resolve_starter_file, get_starter_code_dir
11+
import os
1112

1213
# Create the Blueprint that app.py will register
1314
main = Blueprint("main", __name__)
@@ -19,6 +20,16 @@ def index():
1920
stats = get_project_stats()
2021
return render_template("index.html", stats=stats)
2122

23+
@main.route("/health")
24+
def health_check():
25+
"""
26+
Returns server status. Useful for uptime monitors and Docker health checks.
27+
"""
28+
return jsonify({
29+
"status": "ok",
30+
"version": os.getenv("APP_VERSION", "1.0.0")
31+
}), 200
32+
2233

2334
@main.route("/api/recommend", methods=["POST"])
2435
def recommend():

tests/test_basic.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,14 @@ def test_download_code_found():
279279
client = get_client()
280280
response = client.get("/project/1/download")
281281
assert response.status_code == 200
282+
283+
def test_health_check(client):
284+
response = client.get("/health")
285+
assert response.status_code == 200
286+
data = response.get_json()
287+
assert "status" in data
288+
assert "version" in data
289+
assert data["status"] == "ok"
282290

283291

284292
from utils.recommender import SCORING_WEIGHTS

0 commit comments

Comments
 (0)