pzx-web-api/app/__init__.py

45 lines
1.1 KiB
Python
Raw Normal View History

2023-08-10 12:27:18 +08:00
import os
# from dotenv import load_dotenv
from apiflask import APIFlask
from chassis.flask_nameko import FlaskPooledClusterRpcProxy
from app.config.config import Config
from app.util.common import basedir
rpc = FlaskPooledClusterRpcProxy()
def register_blueprints(apiflask_app):
from app.api.v1 import create_v1
apiflask_app.register_blueprint(create_v1(), url_prefix='/v1')
def load_app_config(app):
"""
加载环境变量和配置类到app config
"""
# 读取 .env
# load_dotenv(os.path.join(basedir, '.apiflask.env'))
# 读取配置类
app.config.from_object('app.config.config.Config')
def load_rpc_client(apiflask_app):
apiflask_app.config.update(dict(
NAMEKO_AMQP_URI=str(Config.RABBITMQ_URI)
))
rpc.init_app(apiflask_app)
def create_app():
# http wsgi server 托管启动需指定读取环境配置
# load_dotenv(os.path.join(basedir, '.apiflaskenv'))
app = APIFlask(__name__, title='Body Record API', version='1.0.0', docs_ui='redoc',
openapi_blueprint_url_prefix='pzx')
2023-08-10 12:27:18 +08:00
load_app_config(app)
register_blueprints(app)
2023-08-11 16:36:56 +08:00
load_rpc_client(app)
2023-08-10 12:27:18 +08:00
return app