Add heartbeat for haproxy; use global domain_root instead of auth_root.
This commit is contained in:
parent
6ca38c13a8
commit
c7de2b8fc2
2 changed files with 11 additions and 2 deletions
5
Dockerfile
Normal file
5
Dockerfile
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
FROM python:3.6-alpine
|
||||||
|
ADD . /code
|
||||||
|
WORKDIR /code
|
||||||
|
RUN pip install -r requirements.txt
|
||||||
|
CMD flask run -h $HOST
|
|
@ -9,7 +9,7 @@ from werkzeug.routing import FloatConverter
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
auth_root = os.environ['AUTH_ROOT']
|
domain_root = os.environ['DOMAIN_ROOT']
|
||||||
ibm_root = os.environ['IBM_API_ROOT']
|
ibm_root = os.environ['IBM_API_ROOT']
|
||||||
|
|
||||||
# For some reason, the standard float converter rejects negative numbers
|
# For some reason, the standard float converter rejects negative numbers
|
||||||
|
@ -31,11 +31,15 @@ class HTTPPaymentRequired(HTTPException):
|
||||||
super().__init__(description, response)
|
super().__init__(description, response)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/heartbeat')
|
||||||
|
def heartbeat():
|
||||||
|
return jsonify({'alive': True})
|
||||||
|
|
||||||
@app.route('/api/v1/geocode/<float:latitude>/<float:longitude>/')
|
@app.route('/api/v1/geocode/<float:latitude>/<float:longitude>/')
|
||||||
def geocode(latitude, longitude):
|
def geocode(latitude, longitude):
|
||||||
if not request.args.get('access_token'):
|
if not request.args.get('access_token'):
|
||||||
abort(401)
|
abort(401)
|
||||||
user_req = requests.get(f"{auth_root}/api/v1/me",
|
user_req = requests.get(f"http://auth.{domain_root}/api/v1/me",
|
||||||
headers={'Authorization': f"Bearer {request.args['access_token']}"})
|
headers={'Authorization': f"Bearer {request.args['access_token']}"})
|
||||||
user_req.raise_for_status()
|
user_req.raise_for_status()
|
||||||
if not user_req.json()['is_subscribed']:
|
if not user_req.json()['is_subscribed']:
|
||||||
|
|
Reference in a new issue