-
Notifications
You must be signed in to change notification settings - Fork 461
/
Copy pathapp.py
38 lines (30 loc) · 872 Bytes
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from flask import Flask
import os
import urllib.request
import json
import dns.resolver
app = Flask(__name__)
BACKEND_RECORD = str(os.getenv("BACKEND_RECORD"))
@app.route('/ping', methods=['GET'])
def healthcheck():
return "ok"
@app.route('/', methods=['GET'])
def inc():
data = {}
answers = dns.resolver.query(BACKEND_RECORD, 'SRV')
domain = ''
port = ''
for rdata in answers:
domain = rdata.target
port = rdata.port
BACKEND_URL = "http://"+str(domain)+":"+str(port)
backend_response = json.loads(urllib.request.urlopen(BACKEND_URL).read())
data['backend_response'] = backend_response['response']
response = app.response_class(
response=json.dumps(data),
status=200,
mimetype='application/json'
)
return response
if __name__ == '__main__':
app.run(host='0.0.0.0', port=80)