2019-04-24 11:57:08 +00:00
|
|
|
from flask import Flask,request,make_response,redirect,url_for,render_template,jsonify
|
|
|
|
from flask_cors import CORS
|
|
|
|
import Jsonfile
|
2019-04-24 17:11:47 +00:00
|
|
|
class ReverseProxied(object):
|
|
|
|
'''Wrap the application in this middleware and configure the
|
|
|
|
front-end server to add these headers, to let you quietly bind
|
|
|
|
this to a URL other than / and to an HTTP scheme that is
|
|
|
|
different than what is used locally.
|
|
|
|
|
|
|
|
In nginx:
|
|
|
|
location /myprefix {
|
|
|
|
proxy_pass http://192.168.0.1:5001;
|
|
|
|
proxy_set_header Host $host;
|
|
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
|
|
proxy_set_header X-Scheme $scheme;
|
|
|
|
proxy_set_header X-Script-Name /myprefix;
|
|
|
|
}
|
|
|
|
|
|
|
|
:param app: the WSGI application
|
|
|
|
'''
|
|
|
|
def __init__(self, app):
|
|
|
|
self.app = app
|
|
|
|
|
|
|
|
def __call__(self, environ, start_response):
|
|
|
|
script_name = environ.get('HTTP_X_SCRIPT_NAME', '')
|
|
|
|
if script_name:
|
|
|
|
environ['SCRIPT_NAME'] = script_name
|
|
|
|
path_info = environ['PATH_INFO']
|
|
|
|
if path_info.startswith(script_name):
|
|
|
|
environ['PATH_INFO'] = path_info[len(script_name):]
|
|
|
|
|
|
|
|
scheme = environ.get('HTTP_X_SCHEME', '')
|
|
|
|
if scheme:
|
|
|
|
environ['wsgi.url_scheme'] = scheme
|
|
|
|
return self.app(environ, start_response)
|
|
|
|
|
|
|
|
|
2019-04-24 11:57:08 +00:00
|
|
|
data= Jsonfile.JSONfile("chaine.json")
|
2019-04-24 13:46:16 +00:00
|
|
|
app=Flask(__name__,static_folder = "dist/static",template_folder="dist")
|
2019-04-24 17:11:47 +00:00
|
|
|
app.wsgi_app = ReverseProxied(app.wsgi_app)
|
2019-04-24 11:57:08 +00:00
|
|
|
CORS(app)
|
|
|
|
@app.route('/')
|
|
|
|
|
|
|
|
def index(path="index.html"):
|
|
|
|
print(path)
|
|
|
|
return render_template(path)
|
|
|
|
|
|
|
|
@app.route('/ping', methods=['GET'])
|
|
|
|
def ping_pong():
|
|
|
|
return jsonify('pong!')
|
|
|
|
|
|
|
|
@app.route('/api/v1/chaine/<num>', methods=['GET'])
|
|
|
|
def get_chaine(num):
|
|
|
|
return jsonify(data.get_chaine(num))
|
|
|
|
|
|
|
|
@app.route('/api/v1/chaine/', methods=['put'])
|
|
|
|
def update_list():
|
|
|
|
data.parsechaine()
|
|
|
|
return "OK"
|
|
|
|
|
|
|
|
##@app.errorhandler(404)
|
|
|
|
##def ma_page_404(error):
|
|
|
|
## return redirect("https://www.ducamps.win/404/404.html", 307)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
app.run(debug=True)
|