Skip to content

Commit

Permalink
Add health endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
robertdijk committed Jan 2, 2024
1 parent 8977ef0 commit 77e61b7
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions narrowcast_content/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,28 @@
# Parse the tokens
tokens = app.config['TOKENS'].split()

def exclude_from_token(func):
func._exclude_from_token = True
return func

@app.route('/health')
@exclude_from_token
def health():
return "slay"

@app.before_request
def check_auth():
"""
Checks if the client sends a token, and if the token is valid.
Puts the token in the session so that it has to be provided only once.
"""

if request.endpoint in app.view_functions:
view_func = app.view_functions[request.endpoint]
check_token = not hasattr(view_func, '_exclude_from_token')
if not check_token:
return

if 'token' not in request.args and 'token' not in session:
abort(401, "Unauthorized")

Expand Down

0 comments on commit 77e61b7

Please sign in to comment.