app.config['SECRET_KEY'] = os.getenv('SECRET_KEY') else: app.config['SECRET_KEY'] = os.getenv('SECRET_KEY', uuid.uuid4().hex) if utils.is_heroku(): app.config.update( SESSION_COOKIE_SECURE=True, SESSION_COOKIE_HTTPONLY=True, SESSION_COOKIE_SAMESITE='Lax', ) # Set security attributes for cookies in a central place - but not when running locally, so that session cookies work well without HTTPS Compress(app) Commonmark(app) parse_logger = jsonbin.MultiParseLogger(jsonbin.JsonBinLogger.from_env_vars(), jsonbin.S3ParseLogger.from_env_vars()) querylog.LOG_QUEUE.set_transmitter( aws_helpers.s3_querylog_transmitter_from_env()) # Check that requested language is supported, otherwise return 404 @app.before_request def check_language(): if requested_lang() not in ALL_LANGUAGES.keys(): return "Language " + requested_lang() + " not supported", 404 if utils.is_heroku() and not os.getenv('HEROKU_RELEASE_CREATED_AT'): logging.warning(
def create_app(config): app = Flask(__name__) config_name = config if not isinstance(config, str): config_name = os.getenv('FLASK_CONFIG', 'default') app.config.from_object(Config[config_name]) app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False app.config['MAX_CONTENT_LENGTH'] = 10 * 1024 * 1024 app.config['UPLOAD_FOLDER'] = 'uploads/' # not using sqlalchemy event system, hence disabling it Config[config_name].init_app(app) # Set up extensions mail.init_app(app) db.init_app(app) login_manager.init_app(app) csrf.init_app(app) compress.init_app(app) babel.init_app(app) RQ(app) # Register Jinja template functions from .utils import register_template_utils register_template_utils(app) # Set up asset pipeline assets_env = Environment(app) dirs = ['assets/styles', 'assets/scripts'] for path in dirs: assets_env.append_path(os.path.join(basedir, path)) assets_env.url_expire = True assets_env.register('app_css', app_css) assets_env.register('default_theme_css', default_theme_css) assets_env.register('dark_theme_css', dark_theme_css) assets_env.register('red_theme_css', red_theme_css) assets_env.register('app_js', app_js) assets_env.register('vendor_css', vendor_css) assets_env.register('vendor_js', vendor_js) # Configure SSL if platform supports it if not app.debug and not app.testing and not app.config['SSL_DISABLE']: from flask_sslify import SSLify SSLify(app) # Create app blueprints from .main import main as main_blueprint app.register_blueprint(main_blueprint) from .main.catalogue import main_constellation as main_constellation app.register_blueprint(main_constellation) from .main.catalogue import main_deepskyobject as main_deepskyobject app.register_blueprint(main_deepskyobject) from .main.catalogue import main_dso_list as main_dso_list app.register_blueprint(main_dso_list) from .main.catalogue import main_star_list as main_star_list app.register_blueprint(main_star_list) from .main.catalogue import main_double_star as main_double_star app.register_blueprint(main_double_star) from .main.location import main_location as main_location app.register_blueprint(main_location) from .main.observation import main_observation as main_observation app.register_blueprint(main_observation) from .main.observation import main_standalone_observation as main_standalone_observation app.register_blueprint(main_standalone_observation) from .main.observation import main_observing_session as main_observing_session app.register_blueprint(main_observing_session) from .main.observation import main_observed as main_observed app.register_blueprint(main_observed) from .main.skyquality import main_sqm as main_sqm app.register_blueprint(main_sqm) from .main.skyquality import main_skyquality as main_skyquality app.register_blueprint(main_skyquality) from .main.userdata import main_userdata as main_userdata app.register_blueprint(main_userdata) from .main.catalogue import main_star as main_star app.register_blueprint(main_star) from .main.usersettings import main_usersettings as main_usersettings app.register_blueprint(main_usersettings) from .main.planner import main_planner as main_planner app.register_blueprint(main_planner) from .main.planner import main_sessionplan as main_sessionplan app.register_blueprint(main_sessionplan) from .main.planner import main_wishlist as main_wishlist app.register_blueprint(main_wishlist) from .main.solarsystem import main_solarsystem as main_solarsystem app.register_blueprint(main_solarsystem) from .main.solarsystem import main_comet as main_comet app.register_blueprint(main_comet) from .main.solarsystem import main_minor_planet as main_minor_panet app.register_blueprint(main_minor_panet) from .main.solarsystem import main_planet as main_planet app.register_blueprint(main_planet) from .main.chart import main_chart as main_chart app.register_blueprint(main_chart) from .main.news import main_news as main_news app.register_blueprint(main_news) from .main.equipment import main_equipment as main_equipment app.register_blueprint(main_equipment) from .main.import_history import main_import_history as main_import_history app.register_blueprint(main_import_history) from .account import account as account_blueprint app.register_blueprint(account_blueprint, url_prefix='/account') from .admin import admin as admin_blueprint app.register_blueprint(admin_blueprint, url_prefix='/admin') from flask_commonmark import Commonmark cm = Commonmark(app) return app