57 lines
1.5 KiB
Python
57 lines
1.5 KiB
Python
from apiflask import APIFlask
|
|
|
|
from dotenv import load_dotenv
|
|
from flask_cors import CORS
|
|
|
|
from models import *
|
|
from blueprint_interface import interface_blueprint
|
|
from api_blueprint_keyword import keyword_blueprint
|
|
from api_blueprint_shares import shares_blueprint
|
|
from api_blueprint_user import users_blueprint
|
|
from api_blueprint_transactions import transaction_blueprint
|
|
from api_blueprint_portfolio import portfolio_blueprint
|
|
|
|
|
|
def create_app():
|
|
load_dotenv()
|
|
|
|
# Create Flask app load app.config
|
|
application = APIFlask(__name__)
|
|
application.config.from_object("config.ConfigClass")
|
|
|
|
CORS(application)
|
|
|
|
application.app_context().push()
|
|
|
|
db.init_app(application)
|
|
|
|
# Create all tables
|
|
db.create_all()
|
|
|
|
# api blueprints
|
|
application.register_blueprint(keyword_blueprint)
|
|
application.register_blueprint(shares_blueprint)
|
|
application.register_blueprint(transaction_blueprint)
|
|
application.register_blueprint(portfolio_blueprint)
|
|
application.register_blueprint(users_blueprint)
|
|
|
|
# interface blueprint
|
|
application.register_blueprint(interface_blueprint)
|
|
|
|
# CORS: Allow * for developing
|
|
@application.after_request # blueprint can also be app~~
|
|
def after_request(response):
|
|
header = response.headers
|
|
header['Access-Control-Allow-Headers'] = 'Content-Type'
|
|
header['Access-Control-Allow-Origin'] = '*'
|
|
return response
|
|
|
|
return application
|
|
|
|
|
|
app = create_app()
|
|
|
|
# Start development web server
|
|
if __name__ == '__main__':
|
|
app.run()
|