Skip to content
Snippets Groups Projects
Commit d0da513c authored by Jan Hartig's avatar Jan Hartig
Browse files

Use whitenoise library for static files

parent 70e41cc5
No related branches found
No related tags found
No related merge requests found
Pipeline #24094 passed
Showing
with 7 additions and 7 deletions
import tomllib
from flask import Flask
from whitenoise import WhiteNoise
# noinspection PyUnresolvedReferences
......@@ -11,6 +12,9 @@ def create_app():
app.config.from_file("config.toml", load=tomllib.load, text=False)
app.config["MAX_CONTENT_LENGTH"] *= 1024 * 1024 * 1024 # bytes -> megabytes -> gigabytes
# static file handling
app.wsgi_app = WhiteNoise(app.wsgi_app, root="static/", prefix="static/", max_age=172800) # 2 days
with open("localisations.toml", "rb") as file:
localisations = tomllib.load(file)
......
......@@ -2,3 +2,4 @@ av~=10.0.0
Flask~=2.3.2
Flask-WTF~=1.1.1
wtforms[email]~=3.0.1
whitenoise~=6.5.0
\ No newline at end of file
......@@ -2,7 +2,7 @@ import json
from os import path, makedirs
from uuid import uuid4
from flask import current_app, render_template, send_from_directory, abort, url_for, redirect, request
from flask import current_app, render_template, abort, url_for, redirect, request
from forms import UploadForm
......@@ -62,11 +62,6 @@ def default():
return redirect(url_for("upload", language="de"))
@current_app.route("/static/<path:name>")
def download_file(name):
return send_from_directory("static", name)
def set_language(language):
if language not in current_app.config["ENABLED_LOCALISATIONS"]:
abort(404)
......
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment