-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement /healthcheck endpoint
implements the healthcheck as a middleware before the HOST_HEADER verification (in django.middleware.common.CommonMiddleware), so healthcheck requests always pass based on https://stackoverflow.com/a/64623669
- Loading branch information
Showing
5 changed files
with
26 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
""" | ||
The core application: middleware definitions for request/response cycle. | ||
""" | ||
|
||
from django.http import HttpResponse | ||
|
||
HEALTHCHECK_PATH = "/healthcheck" | ||
|
||
|
||
class Healthcheck: | ||
"""Middleware intercepts and accepts /healthcheck requests.""" | ||
|
||
def __init__(self, get_response): | ||
self.get_response = get_response | ||
|
||
def __call__(self, request): | ||
if request.path == HEALTHCHECK_PATH: | ||
return HttpResponse("Healthy", content_type="text/plain") | ||
return self.get_response(request) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from pems.core.middleware import HEALTHCHECK_PATH | ||
|
||
|
||
def test_healthcheck(client): | ||
response = client.get(HEALTHCHECK_PATH) | ||
assert response.status_code == 200 |