-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstart_flask.py
37 lines (31 loc) · 1 KB
/
start_flask.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
# flask /wsgi
from gevent.wsgi import WSGIServer
from gevent import monkey
from flask import Flask, request, redirect
from urllib.parse import urlparse, urlunparse
# patch for gevent cooperative tasking
monkey.patch_all()
from backend.api import makeApp
app = makeApp()
'''
@app.before_request
def redirect_eg():
u = urlparse(request.url)
# don't redirect static content to https
# possibel security risk by appending static to a non-static url??
#if '/static/' in u.path:
# return None
# already https
if u.netloc == 'www.eg.bucknell.edu':# and request.is_secure:
# logging.info("NO redirect {}".format(request.url))
return None
# redirect everything else
# logging.info(str(u))
# logging.info(request.headers)
# force https
x = urlunparse(('https', 'www.eg.bucknell.edu') + u[2:])
#logging.info("redirect {} to {}".format(request.url, x))
return redirect(x, code=301)
'''
http_server = WSGIServer(('', 4004), app)
http_server.serve_forever()