From a22aa2bea1542a6d70520757f02db5afe8a75fbd Mon Sep 17 00:00:00 2001 From: trinkey <97406176+trinkey@users.noreply.github.com> Date: Tue, 20 Feb 2024 19:26:24 -0500 Subject: [PATCH] https autoupgrade --- README.md | 2 ++ _server.py | 20 ++++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8bd39ea..6717850 100644 --- a/README.md +++ b/README.md @@ -6,3 +6,5 @@ it's like pronouns.page but i made it ### todo * social links * sexuality/gender flags +* 404 page +* embed meta tags diff --git a/_server.py b/_server.py index 0bbed93..fcc6fbf 100644 --- a/_server.py +++ b/_server.py @@ -1,14 +1,17 @@ +CONTENT_DIRECTORY = "./public/" +SAVING_DIRECTORY = "./save/" + +UPGRADE_TO_HTTPS = False + import hashlib import shutil import flask import json import os -from flask import request from typing import Union, Callable - -CONTENT_DIRECTORY = "./public/" -SAVING_DIRECTORY = "./save/" +from flask import request, redirect +from werkzeug.middleware.proxy_fix import ProxyFix app = flask.Flask(__name__) @@ -311,5 +314,14 @@ app.route("/api/account/info/", methods=["GET"])(api_account_info_) app.route("/api/account/self", methods=["GET"])(api_account_self) app.route("/api/save", methods=["PATCH"])(api_save) +if UPGRADE_TO_HTTPS: + app.wsgi_app = ProxyFix(app.wsgi_app) + + @app.before_request + def enforce_https(): + if not request.is_secure: + url = request.url.replace('http://', 'https://', 1) + return redirect(url, code=301) + if __name__ == "__main__": app.run(debug=True, port=8080)