FitTrackee/fittrackee_api/fittrackee_api/__init__.py

66 lines
2.1 KiB
Python
Raw Normal View History

2017-12-16 21:00:46 +01:00
import logging
2018-04-10 21:53:18 +02:00
import os
2017-12-16 21:00:46 +01:00
from flask import Flask
from flask_bcrypt import Bcrypt
2018-01-20 19:12:34 +01:00
from flask_migrate import Migrate
2017-12-16 21:00:46 +01:00
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
bcrypt = Bcrypt()
2018-01-20 19:12:34 +01:00
migrate = Migrate()
appLog = logging.getLogger('fittrackee_api')
2017-12-16 21:00:46 +01:00
2018-04-09 22:09:58 +02:00
def create_app():
# instantiate the app
app = Flask(__name__)
# set config
with app.app_context():
2018-04-10 21:53:18 +02:00
app_settings = os.getenv('APP_SETTINGS')
app.config.from_object(app_settings)
2018-04-09 22:09:58 +02:00
# set up extensions
db.init_app(app)
bcrypt.init_app(app)
migrate.init_app(app, db)
from .users.auth import auth_blueprint # noqa
from .users.users import users_blueprint # noqa
from .activities.activities import activities_blueprint # noqa
from .activities.records import records_blueprint # noqa
2018-05-01 16:17:12 +02:00
from .activities.sports import sports_blueprint # noqa
2018-06-06 00:22:24 +02:00
from .activities.stats import stats_blueprint # noqa
2018-04-09 22:09:58 +02:00
app.register_blueprint(users_blueprint, url_prefix='/api')
app.register_blueprint(auth_blueprint, url_prefix='/api')
app.register_blueprint(activities_blueprint, url_prefix='/api')
app.register_blueprint(records_blueprint, url_prefix='/api')
2018-05-01 16:17:12 +02:00
app.register_blueprint(sports_blueprint, url_prefix='/api')
2018-06-06 00:22:24 +02:00
app.register_blueprint(stats_blueprint, url_prefix='/api')
2018-04-09 22:09:58 +02:00
if app.debug:
logging.getLogger('sqlalchemy').setLevel(logging.WARNING)
logging.getLogger('sqlalchemy'
).handlers = logging.getLogger('werkzeug').handlers
logging.getLogger('sqlalchemy.orm').setLevel(logging.WARNING)
logging.getLogger('flake8').propagate = False
appLog.setLevel(logging.DEBUG)
if app.debug:
# Enable CORS
@app.after_request
def after_request(response):
response.headers.add('Access-Control-Allow-Origin', '*')
response.headers.add(
'Access-Control-Allow-Headers', 'Content-Type,Authorization'
)
response.headers.add(
'Access-Control-Allow-Methods',
'GET,PUT,POST,DELETE,PATCH,OPTIONS'
)
return response
return app