Revert "Make app object easily accessible from gunicorn"

This reverts commit 6e25af03c4.
This commit is contained in:
Mattéo Delabre 2021-09-12 22:39:23 +02:00
parent 6e25af03c4
commit 33d10c20a1
Signed by: matteo
GPG Key ID: AE3FBD02DC583ABB
1 changed files with 29 additions and 27 deletions

View File

@ -5,35 +5,37 @@ from os import environ
from flask import Flask from flask import Flask
from . import twitch from . import twitch
# Setup logging
debug = environ.get("FLASK_ENV", "production") == "development"
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
level = logging.DEBUG if debug else logging.INFO blueprints = {
logging.basicConfig(level=level) "twitch": twitch,
}
# Read configuration
config_path = environ.get("FEEDLEWARE_CONFIG")
if not config_path: def create_app():
"""Read the app configuration and instantiate service blueprints."""
debug = environ.get("FLASK_ENV", "production") == "development"
level = logging.DEBUG if debug else logging.INFO
logging.basicConfig(level=level)
config_path = environ.get("FEEDLEWARE_CONFIG")
if not config_path:
print( print(
"Please set the FEEDLEWARE_CONFIG environment variable", "Please set the FEEDLEWARE_CONFIG environment variable",
file=sys.stderr, file=sys.stderr,
) )
sys.exit(1) sys.exit(1)
config = configparser.ConfigParser() config = configparser.ConfigParser()
config.read(config_path) config.read(config_path)
app = Flask(__name__)
# Instantiate app and attach blueprints for section in config.sections():
app = Flask(__name__)
blueprints = {
"twitch": twitch,
}
for section in config.sections():
if section in blueprints: if section in blueprints:
blueprint = blueprints[section].create_blueprint(config[section]) blueprint = blueprints[section].create_blueprint(config[section])
app.register_blueprint(blueprint, url_prefix="/" + section) app.register_blueprint(blueprint, url_prefix="/" + section)
else: else:
logger.warning("Unknown service '%s'", section) logger.warning("Unknown service '%s'", section)
return app