Files @ db1c6ce454d0
Branch filter:

Location: C3L-NOC/spaceapi/spaceapi/__init__.py

Dennis Fink
Use abort function in state.py
import json
import os
import os.path
import base64

from flask import Flask

config_file = os.path.abspath('config.json')

def create_app():
	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)

	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]

			return True

		app.config.from_json = from_json

	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')

		return response

	from .views import root_views
	app.register_blueprint(root_views)

	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')

	return app