-
Notifications
You must be signed in to change notification settings - Fork 122
/
app.py
58 lines (45 loc) · 1.92 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from typing import Optional
from flask import Flask, render_template, request
from flask_cors import CORS
from flasgger import Swagger
from api.route.account import account_api
from api.route.schedule import schedule_api
from api.route.batch import batches_api
from api.route.clan import clan_api
from api.route.task import task_api
from api.route.subtask import subtask_api
from api.route.ocr import ocr_api
from utils import STATIC_PATH, DIST_PATH
from werkzeug.routing import BaseConverter
class RegexConverter(BaseConverter):
def __init__(self, url_map, *items):
super(RegexConverter, self).__init__(url_map)
self.regex = items[0]
def create_app():
app = Flask(__name__, static_folder=STATIC_PATH, template_folder=DIST_PATH)
app.url_map.converters['reg'] = RegexConverter
CORS(app, supports_credentials=True)
@app.route('/', defaults={'path': ''})
@app.route('/<reg("((?!(api|apidocs|ocr)).)+"):path>') # 暂 api|apidoc|ocr 以外的所有路由视为前端路由
def index(path):
return render_template("index.html")
app.register_blueprint(account_api, url_prefix='/api')
app.register_blueprint(schedule_api, url_prefix='/api')
app.register_blueprint(clan_api, url_prefix='/api')
app.register_blueprint(task_api, url_prefix='/api')
app.register_blueprint(subtask_api, url_prefix='/api')
app.register_blueprint(batches_api, url_prefix='/api')
app.register_blueprint(ocr_api, url_prefix='/ocr')
app.config['SWAGGER'] = {
'title': 'Princess Connection Farm',
}
Swagger(app)
return app
if __name__ == '__main__':
from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument('-p', '--port', default=5000, type=int, help='port to listen on')
parser.add_argument('-d', '--debug', default=True, type=bool)
args = parser.parse_args()
app = create_app()
app.run(host='127.0.0.1', port=args.port, debug=False)