diff --git a/api/app.py b/api/app.py index ac8bf27df..aea28ac93 100644 --- a/api/app.py +++ b/api/app.py @@ -26,6 +26,7 @@ from config import CloudEditionConfig, Config from extensions import ( ext_celery, ext_code_based_extension, + ext_compress, ext_database, ext_hosting_provider, ext_login, @@ -96,6 +97,7 @@ def create_app(test_config=None) -> Flask: def initialize_extensions(app): # Since the application instance is now created, pass it to each Flask # extension instance to bind it to the Flask application instance (app) + ext_compress.init_app(app) ext_code_based_extension.init() ext_database.init_app(app) ext_migrate.init(app, db) diff --git a/api/config.py b/api/config.py index faf4185c9..7c46426b4 100644 --- a/api/config.py +++ b/api/config.py @@ -293,6 +293,8 @@ class Config: self.BATCH_UPLOAD_LIMIT = get_env('BATCH_UPLOAD_LIMIT') + self.API_COMPRESSION_ENABLED = get_bool_env('API_COMPRESSION_ENABLED') + class CloudEditionConfig(Config): diff --git a/api/extensions/ext_compress.py b/api/extensions/ext_compress.py new file mode 100644 index 000000000..caa61675f --- /dev/null +++ b/api/extensions/ext_compress.py @@ -0,0 +1,10 @@ +from flask import Flask + + +def init_app(app: Flask): + if app.config.get('API_COMPRESSION_ENABLED', False): + from flask_compress import Compress + + compress = Compress() + compress.init_app(app) + diff --git a/api/requirements.txt b/api/requirements.txt index 1c3e89e78..e44c8c941 100644 --- a/api/requirements.txt +++ b/api/requirements.txt @@ -3,6 +3,7 @@ beautifulsoup4==4.12.2 flask~=3.0.1 Flask-SQLAlchemy~=3.0.5 SQLAlchemy~=1.4.28 +Flask-Compress~=1.14 flask-login~=0.6.3 flask-migrate~=4.0.5 flask-restful~=0.3.10