diff --git a/spaceapi/__init__.py b/spaceapi/__init__.py --- a/spaceapi/__init__.py +++ b/spaceapi/__init__.py @@ -7,46 +7,48 @@ from flask import Flask config_file = os.path.abspath('config.json') + def create_app(): - app = Flask(__name__) + app = Flask(__name__) - _default_secret_key = base64.b64encode(os.urandom(32)).decode('utf-8') - app.config['SECRET_KEY'] = os.environ.get('SECRET_KEY', _default_secret_key) + _default_secret_key = base64.b64encode(os.urandom(32)).decode('utf-8') + app.config['SECRET_KEY'] = os.environ.get('SECRET_KEY', + _default_secret_key) - if not hasattr(app.config, 'from_json'): - def from_json(file, silent=True): - try: - with open(file, encoding='utf-8') as json_file: - obj = json.load(json_file) - except IOError: - if silent: - return False - raise + if not hasattr(app.config, 'from_json'): + def from_json(file, silent=True): + try: + with open(file, encoding='utf-8') as json_file: + obj = json.load(json_file) + except IOError: + if silent: + return False + raise - for key in obj: - if key.isupper(): - app.config[key] = obj[key] + for key in obj: + if key.isupper(): + app.config[key] = obj[key] - return True + return True - app.config.from_json = from_json + app.config.from_json = from_json - app.config.from_json(config_file, silent=True) + app.config.from_json(config_file, silent=True) - @app.after_request - def add_headers(response): - response.headers.setdefault('Access-Control-Allow-Origin', '*') - response.headers.setdefault('Cache-Control', 'no-cache') + @app.after_request + def add_headers(response): + response.headers.setdefault('Access-Control-Allow-Origin', '*') + response.headers.setdefault('Cache-Control', 'no-cache') - return response + return response - from .views import root_views - app.register_blueprint(root_views) + from .views import root_views + app.register_blueprint(root_views) - from .state import state_views - app.register_blueprint(state_views, url_prefix='/state') + from .state import state_views + app.register_blueprint(state_views, url_prefix='/state') - from .sensors import sensors_views - app.register_blueprint(sensors_views, url_prefix='/sensors') + from .sensors import sensors_views + app.register_blueprint(sensors_views, url_prefix='/sensors') return app