Added static backend

This commit is contained in:
2026-02-23 13:33:21 +00:00
parent a162ba6841
commit 52db1c3d9b
3 changed files with 42 additions and 0 deletions

26
static.py Normal file
View File

@ -0,0 +1,26 @@
"""
Holds the blueprint for serving the static folder.
THIS WILL ONLY BE FUNCTIONAL IN DEBUG MODE, as Nginx should serve the static folder in production.
"""
import os
import flask
staticBP = flask.Blueprint('staticPage', __name__, static_folder='./www/')
@staticBP.route('/', defaults={'path': 'index.html'})
@staticBP.route('/<path:path>')
def staticPage(path):
"""
Returns anything requested in the static folder.
"""
if not flask.current_app.debug:
# Return forbidden code if trying to access static files in production mode.
flask.abort(403)
if os.path.isfile(os.path.join(staticBP.static_folder, path, 'index.html')):
path = os.path.join(path, 'index.html')
return flask.send_from_directory(staticBP.static_folder, path)