2021-11-29 11:09:21 +08:00
|
|
|
|
import sys
|
|
|
|
|
import os.path
|
2021-11-30 15:55:50 +08:00
|
|
|
|
from logging.config import dictConfig
|
|
|
|
|
|
2021-11-29 11:09:21 +08:00
|
|
|
|
from flask import Flask
|
2021-11-30 15:55:50 +08:00
|
|
|
|
from flask.logging import default_handler
|
2021-11-29 11:09:21 +08:00
|
|
|
|
|
|
|
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
|
|
|
|
|
from database.mongodb import initialize_db
|
2021-12-08 14:33:17 +08:00
|
|
|
|
from api.routes import blueprint_api
|
2021-11-30 15:55:50 +08:00
|
|
|
|
from settings.dev import LOGGING
|
2021-12-06 15:30:21 +08:00
|
|
|
|
from settings.common import INSTANCE, VERSION
|
|
|
|
|
from common.utils import make_response
|
2021-11-30 15:55:50 +08:00
|
|
|
|
|
2021-11-29 11:09:21 +08:00
|
|
|
|
|
2021-11-30 15:55:50 +08:00
|
|
|
|
# 日志配置
|
|
|
|
|
dictConfig(LOGGING)
|
2021-11-29 11:09:21 +08:00
|
|
|
|
|
2021-11-30 15:55:50 +08:00
|
|
|
|
# app 实例,移除默认日志,加载配置文件
|
2021-11-29 11:09:21 +08:00
|
|
|
|
app = Flask(__name__)
|
2021-11-30 15:55:50 +08:00
|
|
|
|
app.logger.removeHandler(default_handler)
|
2021-11-29 11:09:21 +08:00
|
|
|
|
app.config.from_pyfile("settings/dev.py")
|
|
|
|
|
|
2021-11-30 15:55:50 +08:00
|
|
|
|
# 初始化数据库连接
|
2021-11-29 11:09:21 +08:00
|
|
|
|
initialize_db(app)
|
|
|
|
|
|
|
|
|
|
# 注册蓝图
|
|
|
|
|
app.register_blueprint(blueprint_api)
|
|
|
|
|
|
|
|
|
|
|
2021-12-06 15:30:21 +08:00
|
|
|
|
@app.after_request
|
|
|
|
|
def mark_global_header(resp):
|
|
|
|
|
"""全局 header """
|
|
|
|
|
# 标记当前提供服务的实例
|
|
|
|
|
resp.headers["Instance"] = INSTANCE
|
|
|
|
|
return resp
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/info')
|
|
|
|
|
def app_info():
|
|
|
|
|
"""返回实例信息,实例版本、实例ID"""
|
|
|
|
|
return make_response(200, 1000, "success", version=VERSION, instance=INSTANCE)
|
|
|
|
|
|
|
|
|
|
|
2021-11-29 11:09:21 +08:00
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
app.run(host='0.0.0.0', port=5001, debug=True)
|
|
|
|
|
|