-
Notifications
You must be signed in to change notification settings - Fork 0
/
flask_web.py
77 lines (64 loc) · 2.64 KB
/
flask_web.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from flask import Flask, json
from flask import render_template
from flask import request
from flask import Response
import requests
app = Flask(__name__)
app.config['MAX_CONTENT_LENGTH'] = 1024*1024*1024
def handleError(e):
logging.error(e)
def getSecuredContent(request, name):
try:
result = urllib2.urlopen("http://"+name).read()
return HttpResponse(result, mimetype='application/javascript')
except urllib2.URLError, e:
handleError(e)
def getSecuredJSONContent(request, name):
try:
full_path = request.get_full_path()
lr_path = full_path[10:]
full_uri = lr_url + lr_path
result = urllib2.urlopen(full_uri).read()
return Response(result, mimetype='application/javascript')
except urllib2.URLError, e:
handleError(e)
@app.route("/")
def proxy():
return render_template("widget.html")
@app.route("/json/<path:path>", methods=['GET', 'POST'])
def jsonproxy(path):
if request.method == "POST":
r = requests.post("http://"+path, data=request.form, headers=request.headers)
return Response(r.content.replace("http:\/\/launchrock-assetmanager","\/\/launchrock-assetmanager"), mimetype='application/json')
else:
r = requests.get("http://"+path, headers=request.headers)
return r.content.replace("http:\/\/","\/\/")
return ","+path+request.method+"".join(request.headers.values())
@app.route("/javascript/<path:path>", methods=['GET', 'POST'])
def jsproxy(path):
if request.method == "POST":
r = requests.post("http://"+path, data=request.form, headers=request.headers)
return Response(r.content.replace("//platform.launchrock.com/v1/","/json/platform.launchrock.com/v1/"), mimetype='application/javascript')
else:
print path
print request.headers
r = requests.get("http://"+path)
print path[-4:]
if path[-4:] == ".css":
return Response(r.content.replace("//platform.launchrock.com/v1/","/json/platform.launchrock.com/v1/"),mimetype="text/css")
else:
return Response(r.content.replace("//platform.launchrock.com/v1/","/json/platform.launchrock.com/v1/"),mimetype="application/javascript")
@app.route("/<path:path>", methods=['GET'])
def imgproxy(path):
if request.method == "POST":
r = requests.post("http://ignition.launchrock.com/"+path, data=request.form, headers=request.headers)
return Response(r.content.replace("//platform.launchrock.com/v1/","/json/platform.launchrock.com/v1/"), mimetype='application/javascript')
else:
print path
print request.headers
r = requests.get("http://aftercoupon.launchrock.com/"+path)
print r.content
return Response(r.content, mimetype="image/png")
if __name__ == "__main__":
app.debug = True
app.run()