-
Notifications
You must be signed in to change notification settings - Fork 51
/
app.py
43 lines (36 loc) · 1.34 KB
/
app.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
import logging
import sys
from waitress import serve
from mod import check_update
from mod.args import GlobalArgs
from mod.dev.debugger import debugger
from api import *
from api import __import__
args = GlobalArgs()
def run_server(debug=False):
if not debug:
# Waitress WSGI 服务器
serve(app, host=args.ip, port=args.port, threads=32, channel_timeout=30)
else:
debugger.debug = True
debugger.log("info", "Debug模式已开启")
debugger.log("info", f"Version: {args.version}")
if args.auth:
debugger.log("info", f"Auth: {args.auth}")
app.run(host='*', port=args.port, debug=True)
if __name__ == '__main__':
# 对Python版本进行检查(要求Python 3.10+)
if sys.version_info < (3, 10):
raise RuntimeError(
"Python 3.10+ required, but you are using Python {}.{}.{}.".format(*sys.version_info[:3])
)
# 日志配置
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
logger = logging.getLogger('')
logger.info("正在启动服务器")
logger.info("您可通过爱发电支持我们,爱发电主页 https://afdian.com/a/ghacg")
check_update.run(version=args.version)
# 注册 Blueprint 到 Flask 应用
app.register_blueprint(v1_bp)
# 启动
run_server(args.debug)