From 357632e46511eef5d42a7ecc118eba142da5e42b Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Thu, 2 Nov 2023 19:11:12 +1100 Subject: [PATCH] fit: Render 404 page on error --- server.py | 17 ++++++++++++++++- templates/404.html | 9 ++++----- templates/index.html | 2 +- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/server.py b/server.py index 07aa1a5..3abe11c 100644 --- a/server.py +++ b/server.py @@ -12,13 +12,28 @@ def send_report(path): @app.route('/') def index(): + https_redirect="" + # Get host from request host = request.headers.get('host') tld = host.split('.')[-1] tld = tld.split(':')[0] if tld == 'localhost' or tld == '1': tld = 'example' - return render_template('index.html', tld=tld) + https_redirect = "" + + + return render_template('index.html', tld=tld, https_redirect=https_redirect) + +# 404 catch all +@app.errorhandler(404) +def not_found(e): + host = request.headers.get('host') + tld = host.split('.')[-1] + tld = tld.split(':')[0] + if tld == 'localhost' or tld == '1': + tld = 'example' + return render_template('404.html', tld=tld), 404 if __name__ == '__main__': app.run(debug=False, port=5000, host='0.0.0.0') \ No newline at end of file diff --git a/templates/404.html b/templates/404.html index 1d0b40a..660230b 100644 --- a/templates/404.html +++ b/templates/404.html @@ -4,7 +4,7 @@ - .tas/ domains + .{{tld}}/ domains @@ -21,7 +21,7 @@
this_page.not_found = true; if (you_spelt_it_wrong){
autocorrect.enable();
}
-else if (we_screwed_up){
alert("Strewth mate, you're lost! Fair dinkum, why are you here?");
window.location = home;
}
+else if (!exists(location)){
alert("You're lost! I'll send you back home");
window.location = home;
}
@@ -30,13 +30,12 @@ diff --git a/templates/index.html b/templates/index.html index f00705a..404f1dd 100644 --- a/templates/index.html +++ b/templates/index.html @@ -46,7 +46,7 @@ Nathan.Woodburn/ - + {{https_redirect | safe}}