-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
41 additions
and
7 deletions.
There are no files selected for viewing
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,16 @@ | ||
|
||
from fastapi.middleware.trustedhost import TrustedHostMiddleware | ||
from starlette.types import Receive, Scope, Send | ||
|
||
|
||
class TrustedHostHealthRoutes(TrustedHostMiddleware): | ||
"""A healthcheck endpoint that answers to GET requests on /_health""" | ||
|
||
|
||
async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None: | ||
"""If the request is made on the path _health then execute the check on hosts""" | ||
if scope["path"] == "/_health/": | ||
print(scope) | ||
await super().__call__(scope, receive, send) | ||
else: | ||
await self.app(scope, receive, send) |
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
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
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,10 @@ | ||
|
||
from fastapi import APIRouter, Response | ||
|
||
router = APIRouter(prefix="/_health") | ||
|
||
|
||
@router.get("/", status_code=200) | ||
def healthcheck(): | ||
"""Healthcheck endpoint that answers to GET requests on /_healthz""" | ||
return Response(status_code=200) |
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