-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
30 lines (22 loc) · 835 Bytes
/
server.py
File metadata and controls
30 lines (22 loc) · 835 Bytes
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
from flask import Flask, request
import os
import urllib.request
replica = os.environ.get('CS_REPLICA')
server = os.environ.get('CS_SERVER')
port = int(os.environ.get('PORT'))
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'], defaults={'path': ''})
@app.route('/<path:path>', methods=['GET', 'POST'])
def catch_all(path):
redirect_url = request.args.get('redirect')
if redirect_url:
try:
contents = urllib.request.urlopen(redirect_url).read()
return contents
except requests.exceptions.RequestException as e:
return jsonify({"error": str(e)}), 400
return jsonify({"message": "No redirect URL provided"}), 400
else:
return f'Response:{server}:{replica}:{port}:/{path}'
if __name__ == '__main__':
app.run(host='0.0.0.0', port=port)