[ Flask跨域配置 ]


import os
from flask import Flask
from flask_cors import CORS


def create_app(config=None) -> Flask:
    print('创建App')
    # create and configure the app
    app = Flask(__name__, instance_relative_config=True)

    app.config.from_mapping(
        SECRET_KEY='dev',
        # DATABASE=os.path.join(app.instance_path, 'flaskr.sqlite'),
    )

    if config is None:
        # load the instance config, if it exists, when not testing
        app.config.from_pyfile(
            app.instance_path / 'applications' / 'config' / 'config.py', silent=True)
    else:
        # load the test config if passed in
        app.config.from_object(config['dev'])

    # ensure the instance folder exists
    try:
        os.makedirs(app.instance_path)
    except OSError:
        pass

    CORS(app)

    # 初始化app
    from applications.extensions import init_plugs
    init_plugs(app)

    # 初始化蓝图
    from applications.views import register_view
    register_view(app)

    return app