Skip to content

Commit 75a1a73

Browse files
committed
Added healtcheck
1 parent 7f78ab2 commit 75a1a73

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

project/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,12 @@ def __init__(self, app, prefix=''):
5252
self.prefix = prefix
5353

5454
def __call__(self, environ, start_response):
55-
5655
if environ['PATH_INFO'].startswith(self.prefix):
5756
environ['PATH_INFO'] = environ['PATH_INFO'][len(self.prefix):]
5857
environ['SCRIPT_NAME'] = self.prefix
5958
return self.app(environ, start_response)
59+
elif environ['PATH_INFO'].startswith("/healthcheck"):
60+
return self.app(environ, start_response)
6061
else:
6162
start_response('404', [('Content-Type', 'text/plain')])
6263
return ["This url does not belong to the app.".encode()]
@@ -65,6 +66,7 @@ def __call__(self, environ, start_response):
6566
def create_app():
6667
from project.models import db
6768
from project.views import views_bp as views_blueprint
69+
from project.views import views_hc as views_hc_blueprint
6870
environment = os.environ.get("ENVIRONMENT", "default")
6971

7072
app = Flask(__name__)
@@ -88,6 +90,7 @@ def create_app():
8890
Swagger(app, config=SWAGGER_CONFIG)
8991

9092
app.register_blueprint(views_blueprint)
93+
app.register_blueprint(views_hc_blueprint)
9194
with app.test_request_context():
9295
db.create_all()
9396
return app, db

project/views/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
from flask import Blueprint
55

66
views_bp = Blueprint('views', __name__, static_url_path='/static')
7+
views_hc = Blueprint('healthcheck', __name__, static_url_path='/static')
78

8-
from project.views import views
9+
from project.views import views, healthcheck

project/views/healthcheck.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from project.views import views_hc
2+
3+
4+
@views_hc.route('/healthcheck', methods=['GET'])
5+
def healthcheck():
6+
return "OK"

0 commit comments

Comments
 (0)