Skip to content

Commit

Permalink
Add the endpoint for the healthcheck.
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptcoin-junkey committed Oct 7, 2018
1 parent bb8dab4 commit 7f7b430
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions counterpartylib/lib/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,16 @@ def _set_cors_headers(response):
response.headers['Access-Control-Allow-Methods'] = 'GET, POST, OPTIONS'
response.headers['Access-Control-Allow-Headers'] = 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization'

@app.route('/healthz', methods=['GET'])
def handle_healthz():
msg, code = 'Healthy', 200
try:
latestBlockIndex = backend.getblockcount()
check_database_state(self.db, latestBlockIndex)
except DatabaseError:
msg, code = 'Unhealthy', 503
return flask.Response(msg, code, mimetype='text/plain')

@app.route('/', defaults={'args_path': ''}, methods=['GET', 'POST', 'OPTIONS'])
@app.route('/<path:args_path>', methods=['GET', 'POST', 'OPTIONS'])
# Only require authentication if RPC_PASSWORD is set.
Expand Down

0 comments on commit 7f7b430

Please sign in to comment.