diff options
author | mjfernez <mjfernez@gmail.com> | 2021-10-06 21:47:10 -0400 |
---|---|---|
committer | mjfernez <mjfernez@gmail.com> | 2021-10-06 21:47:10 -0400 |
commit | a800163aeae0998fa49f011664f32a6c348db886 (patch) | |
tree | 0e9dc38ad5c1fac12ee07f5f6c1fa5ab178330eb | |
parent | 6ddd97e1c39f55fe60fca093ca4fe610eca6d462 (diff) | |
download | ezcms-a800163aeae0998fa49f011664f32a6c348db886.tar.gz |
Adds gzip support by default
This commit adds Flask-Compress to the stack, an excellent module that
makes the site load faster. This also adds and amends the default
siteconfig
-rw-r--r-- | requirements.txt | 1 | ||||
-rw-r--r-- | server.py | 5 | ||||
-rw-r--r-- | siteconfig.py | 18 |
3 files changed, 17 insertions, 7 deletions
diff --git a/requirements.txt b/requirements.txt index a753d36..63d0835 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,3 +6,4 @@ MarkupSafe==2.0.1 pip==20.3.4 setuptools==44.1.1 Werkzeug==2.0.1 +Flask-Compress==1.10.1 @@ -1,8 +1,10 @@ import os from flask import Flask from siteconfig import siteconfig +from flask_compress import Compress app = Flask(__name__) +compress = Compress() from views import * @@ -30,9 +32,10 @@ def setup(): app.config.update({'DOMAIN': siteconfig.DOMAIN}) app.config.update({'HOME_TITLE': siteconfig.HOME_TITLE}) - + app.config.update({'COMPRESS_MIMETYPES': siteconfig.COMPRESS_MIMETYPES}) # Setup needs to come first to be compatible with wsgi setup() if __name__ == "__main__": + compress.init_app(app) app.run() diff --git a/siteconfig.py b/siteconfig.py index 3a0229f..fa73b46 100644 --- a/siteconfig.py +++ b/siteconfig.py @@ -1,12 +1,16 @@ class siteconfig: # REQUIRED SETTINGS# - + DOMAIN = "example.net" # Your site here! - HOME_TITLE = "WELCOME" # "HELLO WORLD!" + HOME_TITLE = "WELCOME" # Goes right under + # your site LINKS_FILE = ".links" # ".lnx" if you like DESC_FILE = ".description" # ".desc" - DEFAULT_MIMETYPE = "application/octet-stream" # "text/plain" - + DEFAULT_MIMETYPE = "application/octet-stream" + # ^This usually prompts a browser to download a file if the mime + # type is unknown. A good alternative might be "text/plain" + + # Add your desired mimetypes to the csv file MIMETYPES = {} with open('mimetypes.csv') as f: for line in f.readlines(): @@ -21,5 +25,7 @@ class siteconfig: MAIN_SITE_DIRS = None # ["dir1", "dir2", "dir3"] # Set a custom secret key. If not set, it will be generated # Most of the time, you don't need to set this! - SECRET_KEY = None # Something random. - + SECRET_KEY = None # Something random. + # Special option for Flask Compress + # see here https://pypi.org/project/Flask-Compress/ + COMPRESS_MIMETYPES = list(MIMETYPES.values()) |