forked from ourresearch/unpaywall-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
views.py
101 lines (65 loc) · 1.93 KB
/
views.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
78
79
80
81
82
83
84
from flask import make_response
from flask import request
from flask import redirect
from flask import abort
from flask import render_template
from flask import jsonify
from flask import g
import json
import os
import sys
from app import app
#support CORS
@app.after_request
def add_crossdomain_header(resp):
resp.headers['Access-Control-Allow-Origin'] = "*"
resp.headers['Access-Control-Allow-Methods'] = "POST, GET, OPTIONS, PUT, DELETE, PATCH"
resp.headers['Access-Control-Allow-Headers'] = "origin, content-type, accept, x-requested-with"
# without this jason's heroku local buffers forever
sys.stdout.flush()
return resp
@app.before_request
def do_before_request():
pass
# if request.url.startswith("http://www.oadoi.org"):
#
# new_url = request.url.replace(
# "http://www.oadoi.org",
# "http://oadoi.org"
# )
# return redirect(new_url, 301) # permanent
#
# g.use_cache = True
# if ('no-cache', u'') in request.args.items():
# g.use_cache = False
# print "NOT USING CACHE"
@app.route("/<path:page>") # from http://stackoverflow.com/a/14023930/226013
@app.route("/")
def index_endpoint(path="index", page=""):
return render_template(
'index.html'
)
def show_welcome_screen(ip):
blacklist = [
"129.107.37.",
"129.107.73.",
"129.107.72.",
"129.107.67.",
"129.107.76."
]
for blacklisted_ip in blacklist:
if ip.startswith(blacklisted_ip):
return False
return True
@app.route("/log/install", methods=["POST", "GET"])
def log_install():
ip = request.remote_addr
return jsonify(
{
"show_welcome_screen": show_welcome_screen(ip),
"ip": ip
}
)
if __name__ == "__main__":
port = int(os.environ.get("PORT", 5010))
app.run(host='0.0.0.0', port=port, debug=True, threaded=True)