Skip to content

Commit a33b2ee

Browse files
committed
add a healthcheck endpoint
1 parent 6250a23 commit a33b2ee

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

compose.override.LOCAL_COPY.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ services:
2424
- 8010:8010
2525
command: ["python", "manage.py", "run", "-h", "0.0.0.0", "-p", "8010"]
2626
healthcheck:
27-
test: ["CMD-SHELL", "curl --fail http://0.0.0.0:8010 || exit 1"]
27+
test: ["CMD-SHELL", "curl --fail http://0.0.0.0:8010/healthcheck || exit 1"]
2828
interval: 1m30s
2929
start_period: 15s
3030
retries: 3

services/backend/project/__init__.py

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
11
from flask import Flask, jsonify
2+
# from flask.views import View
23

34

45
app = Flask(__name__)
56

67

7-
@app.route("/generate/")
8+
@app.route("/api/")
89
def hello_world():
9-
return jsonify(hi="Sopi")
10+
return jsonify(hello="World")
11+
12+
13+
# class Health(View):
14+
# def get(self):
15+
# data = {"success": True, "message": "healthy"}
16+
# return jsonify(**data, status=200, mimetype='application/json')
17+
18+
# app.add_url_rule("/healthcheck", view_func=Health.as_view("health_check"))
19+
20+
21+
@app.route("/healthcheck", strict_slashes=False)
22+
def health_check():
23+
data = {"success": True, "message": "healthy"}
24+
return jsonify(**data, status=200, mimetype='application/json')

services/nginx/dev/nginx.conf

+11-2
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,21 @@ http {
2020
listen 80;
2121
client_max_body_size 500M;
2222

23-
location ~ ^/generate/(.*)$ {
23+
location ~ ^/api/(.*)$ {
2424
# If we set the upstream host as a variable here it causes nginx to NOT crash during bootup.
2525
# This allows us to start nginx without needing all the upstream services started (we only need to start what we want)
2626
set $upstream http://backend:8010;
2727
# $1 is the path from regex and $is_args$args are the query params which we pass to the upstream.
28-
proxy_pass $upstream/generate/$1$is_args$args;
28+
proxy_pass $upstream/api/$1$is_args$args;
29+
proxy_redirect off;
30+
}
31+
32+
location ~ ^/healthcheck {
33+
# If we set the upstream host as a variable here it causes nginx to NOT crash during bootup.
34+
# This allows us to start nginx without needing all the upstream services started (we only need to start what we want)
35+
set $upstream http://backend:8010;
36+
# $1 is the path from regex and $is_args$args are the query params which we pass to the upstream.
37+
proxy_pass $upstream/healthcheck/$1$is_args$args;
2938
proxy_redirect off;
3039
}
3140

0 commit comments

Comments
 (0)