2020-04-06 20:14:19 +08:00
|
|
|
from flask import Flask
|
|
|
|
from flask_cors import CORS
|
|
|
|
from flask_mail import Mail
|
|
|
|
from werkzeug.middleware.proxy_fix import ProxyFix
|
|
|
|
|
|
|
|
import config
|
|
|
|
|
|
|
|
|
|
|
|
mail = Mail()
|
|
|
|
|
|
|
|
|
|
|
|
def create_app(cfg=config):
|
|
|
|
app = Flask(__name__)
|
|
|
|
app.config.from_object(cfg)
|
|
|
|
app.wsgi_app = ProxyFix(app.wsgi_app)
|
|
|
|
|
|
|
|
mail.init_app(app)
|
|
|
|
|
|
|
|
from app.api import bp as bp_api
|
|
|
|
|
|
|
|
app.register_blueprint(bp_api)
|
|
|
|
|
|
|
|
CORS(
|
|
|
|
app,
|
|
|
|
resources={r'/api/*': {
|
2020-04-14 13:19:30 +08:00
|
|
|
'methods': ['POST', 'OPTIONS'],
|
|
|
|
'allow_origins': app.config['CORS_ALLOWED_ORIGINS'].split(','),
|
|
|
|
'allow_headers': app.config['CORS_ALLOWED_HEADERS'].split(','),
|
2020-04-06 20:14:19 +08:00
|
|
|
}})
|
|
|
|
|
|
|
|
return app
|