From 44a5da1895acf733b2b984839d23d1196c80af54 Mon Sep 17 00:00:00 2001 From: Ben Busby Date: Sat, 5 Dec 2020 15:51:06 -0500 Subject: [PATCH] Fix heroku https upgrade, add funding options Heroku app instances have been notoriously bad at having the instance automatically upgraded to https. This adds a step in the before request decorator to always upgrade heroku apps, since they're always deployed with the certificate, but never configured to upgrade automatically. Fixes #153 --- .github/FUNDING.yml | 9 +++++++++ app/routes.py | 6 ++++-- 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..e674a22 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,9 @@ +# These are supported funding model platforms +github: benbusby +ko_fi: benbusby +tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel +community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry +liberapay: # Replace with a single Liberapay username +issuehunt: # Replace with a single IssueHunt username +otechie: # Replace with a single Otechie username +custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] diff --git a/app/routes.py b/app/routes.py index 90b525a..dba4b54 100644 --- a/app/routes.py +++ b/app/routes.py @@ -57,10 +57,12 @@ def before_request_func(): if session['uuid'] not in app.user_elements: app.user_elements.update({session['uuid']: 0}) - # Always redirect to https if HTTPS_ONLY is set (otherwise default to False) + # Handle https upgrade https_only = os.getenv('HTTPS_ONLY', False) + is_heroku = request.url.endswith('.herokuapp.com') + is_http = request.url.startswith('http://') - if https_only and request.url.startswith('http://'): + if (is_heroku and is_http) or (https_only and is_http): return redirect(request.url.replace('http://', 'https://', 1), code=308) g.user_config = Config(**session['config'])