diff --git a/.env.example b/.env.example index f41bfdb..6ab850b 100644 --- a/.env.example +++ b/.env.example @@ -87,4 +87,35 @@ ENABLE_PP=0 # DEBUG_MODE: # Czy uruchomić aplikację w trybie debugowania (z konsolą błędów i autoreloaderem) # Domyślnie: 1 -DEBUG_MODE=1 \ No newline at end of file +DEBUG_MODE=1 + +# DISABLE_ROBOTS: +# Czy zablokować indeksowanie przez roboty (serwuje robots.txt z Disallow: /) +# Domyślnie: 0 +DISABLE_ROBOTS=0 + +# JS_CACHE_CONTROL: +# Nagłówki Cache-Control dla plików JS (/static/js/) +# Domyślnie: "no-cache, no-store, must-revalidate" +JS_CACHE_CONTROL="no-cache, no-store, must-revalidate" + +# CSS_CACHE_CONTROL: +# Nagłówki Cache-Control dla plików CSS (/static/css/) +# Domyślnie: "public, max-age=3600" +CSS_CACHE_CONTROL="public, max-age=3600" + +# LIB_JS_CACHE_CONTROL: +# Nagłówki Cache-Control dla bibliotek JS (/static/lib/js/) +# Domyślnie: "public, max-age=604800" +LIB_JS_CACHE_CONTROL="public, max-age=604800" + +# LIB_CSS_CACHE_CONTROL: +# Nagłówki Cache-Control dla bibliotek CSS (/static/lib/css/) +# Domyślnie: "public, max-age=604800" +LIB_CSS_CACHE_CONTROL="public, max-age=604800" + +# UPLOADS_CACHE_CONTROL: +# Nagłówki Cache-Control dla wgrywanych plików (/uploads/) +# Domyślnie: "public, max-age=2592000, immutable" +UPLOADS_CACHE_CONTROL="public, max-age=2592000, immutable" + diff --git a/app.py b/app.py index 98ac28e..41ef614 100644 --- a/app.py +++ b/app.py @@ -227,11 +227,10 @@ with app.app_context(): @static_bp.route("/static/js/") def serve_js(filename): response = send_from_directory("static/js", filename) - response.cache_control.no_cache = True - response.cache_control.no_store = True - response.cache_control.must_revalidate = True - # response.expires = 0 - response.pragma = "no-cache" + #response.cache_control.no_cache = True + #response.cache_control.no_store = True + #response.cache_control.must_revalidate = True + response.headers["Cache-Control"] = app.config["JS_CACHE_CONTROL"] response.headers.pop("Content-Disposition", None) response.headers.pop("Etag", None) return response @@ -240,7 +239,7 @@ def serve_js(filename): @static_bp.route("/static/css/") def serve_css(filename): response = send_from_directory("static/css", filename) - response.headers["Cache-Control"] = "public, max-age=3600" + response.headers["Cache-Control"] = app.config["CSS_CACHE_CONTROL"] response.headers.pop("Content-Disposition", None) response.headers.pop("Etag", None) return response @@ -249,7 +248,7 @@ def serve_css(filename): @static_bp.route("/static/lib/js/") def serve_js_lib(filename): response = send_from_directory("static/lib/js", filename) - response.headers["Cache-Control"] = "public, max-age=604800" + response.headers["Cache-Control"] = app.config["LIB_JS_CACHE_CONTROL"] response.headers.pop("Content-Disposition", None) response.headers.pop("Etag", None) return response @@ -259,7 +258,7 @@ def serve_js_lib(filename): @static_bp.route("/static/lib/css/") def serve_css_lib(filename): response = send_from_directory("static/lib/css", filename) - response.headers["Cache-Control"] = "public, max-age=604800" + response.headers["Cache-Control"] = app.config["LIB_CSS_CACHE_CONTROL"] response.headers.pop("Content-Disposition", None) response.headers.pop("Etag", None) return response @@ -1308,7 +1307,7 @@ def upload_receipt(list_id): @app.route("/uploads/") def uploaded_file(filename): response = send_from_directory(app.config["UPLOAD_FOLDER"], filename) - response.headers["Cache-Control"] = "public, max-age=2592000, immutable" + response.headers["Cache-Control"] = app.config["UPLOADS_CACHE_CONTROL"] response.headers.pop("Pragma", None) response.headers.pop("Content-Disposition", None) mime, _ = mimetypes.guess_type(filename) @@ -2230,6 +2229,13 @@ def healthcheck(): abort(404) return "OK", 200 +@app.route("/robots.txt") +def robots_txt(): + if app.config.get("DISABLE_ROBOTS", False): + return "User-agent: *\nDisallow: /", 200, {"Content-Type": "text/plain"} + return "User-agent: *\nAllow: /", 200, {"Content-Type": "text/plain"} + + # ========================================================================================= # SOCKET.IO # ========================================================================================= diff --git a/config.py b/config.py index a4408bc..bf94a7b 100644 --- a/config.py +++ b/config.py @@ -37,4 +37,10 @@ class Config: ENABLE_CSP = os.environ.get("ENABLE_CSP", "0") == "1" ENABLE_PP = os.environ.get("ENABLE_PP", "0") == "1" - DEBUG_MODE = os.environ.get("DEBUG_MODE", "1") == "1" \ No newline at end of file + DEBUG_MODE = os.environ.get("DEBUG_MODE", "1") == "1" + DISABLE_ROBOTS = os.environ.get("DISABLE_ROBOTS", "0") == "1" + JS_CACHE_CONTROL = os.environ.get("JS_CACHE_CONTROL", "no-cache, no-store, must-revalidate") + CSS_CACHE_CONTROL = os.environ.get("CSS_CACHE_CONTROL", "public, max-age=3600") + LIB_JS_CACHE_CONTROL = os.environ.get("LIB_JS_CACHE_CONTROL", "public, max-age=604800") + LIB_CSS_CACHE_CONTROL = os.environ.get("LIB_CSS_CACHE_CONTROL", "public, max-age=604800") + UPLOADS_CACHE_CONTROL = os.environ.get("UPLOADS_CACHE_CONTROL", "public, max-age=2592000, immutable") \ No newline at end of file