58 lines
1.4 KiB
Python
58 lines
1.4 KiB
Python
from gevent import pywsgi, monkey
|
|
monkey.patch_all()
|
|
|
|
import cosmic
|
|
import tidi
|
|
from utils import *
|
|
import saber
|
|
import radar
|
|
import balloon
|
|
from flask import Flask, request
|
|
from flask_cors import CORS
|
|
from typing import get_args
|
|
import sys
|
|
import matplotlib.font_manager as fm
|
|
|
|
app = Flask(__name__)
|
|
CORS(app)
|
|
|
|
fm.fontManager.addfont("./SimHei.ttf")
|
|
@app.before_request
|
|
def auth():
|
|
# check for method
|
|
# if it is OPTIONS, do not check for auth
|
|
if request.method == "OPTIONS":
|
|
return
|
|
code = request.headers.get("Authorization")
|
|
print(code)
|
|
if code != "0101":
|
|
return "Unauthorized", 401
|
|
|
|
@app.route("/ping")
|
|
def ping():
|
|
return "pong"
|
|
|
|
app.register_blueprint(balloon.balloon_module, url_prefix="/balloon")
|
|
app.register_blueprint(radar.radar_module, url_prefix="/radar")
|
|
app.register_blueprint(saber.saber_module, url_prefix="/saber")
|
|
app.register_blueprint(tidi.tidi_module, url_prefix="/tidi")
|
|
app.register_blueprint(cosmic.cosmic_module, url_prefix="/cosmic")
|
|
# allow cors
|
|
CORS(app)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
# get args '--prod'
|
|
args = sys.argv
|
|
if 'prod' in args:
|
|
|
|
# app.run()
|
|
# import gevent
|
|
server = pywsgi.WSGIServer(('0.0.0.0', 5000), app)
|
|
server.serve_forever()
|
|
|
|
elif 'debug' in args:
|
|
app.run("0.0.0.0",port=18200,debug=True)
|
|
else:
|
|
raise Exception("Invalied")
|