-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathmain.py
57 lines (43 loc) · 1.35 KB
/
main.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
import logging
import os
import sys
from flask import Flask, jsonify, render_template
from flask_cors import CORS
from gevent import monkey
from gevent.pywsgi import WSGIServer
from altfe import bridge, handle
from altfe.interface.root import classRoot
monkey.patch_all()
app = Flask(__name__)
rootPath = os.path.split(os.path.realpath(sys.argv[0]))[0] + "/"
rootPathFrozen = sys._MEIPASS + "/" if getattr(sys, "frozen", False) else rootPath
# CORS(app, resources=r"/*")
# 路由
@app.route("/")
def render():
return render_template("md.html")
@app.route("/<path:path>", methods=["GET", "POST"])
def run(path):
rep = handle.handleRoute.do(path)
if type(rep) == dict:
code = rep["code"]
if code == 0:
status = 400
elif code == 1:
status = 200
else:
status = code
return jsonify(rep), status
else:
return rep
if __name__ == "__main__":
# Altfe 框架初始化
classRoot.setENV("rootPath", rootPath)
classRoot.setENV("rootPathFrozen", rootPathFrozen)
bridge.bridgeInit().run(hint=True)
# 调整日志等级
logging.getLogger("werkzeug").setLevel(logging.ERROR)
# 启动
# app.run(host="127.0.0.1", port=5000, debug=True, threaded=True, use_reloader=False)
http_server = WSGIServer(("0.0.0.0", 5000), app)
http_server.serve_forever()