fit: Render 404 page on error
All checks were successful
Build Docker / Build Image (push) Successful in 22s

This commit is contained in:
Nathan Woodburn 2023-11-02 19:11:12 +11:00
parent 81660ae769
commit 357632e465
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
3 changed files with 21 additions and 7 deletions

View File

@ -12,13 +12,28 @@ def send_report(path):
@app.route('/') @app.route('/')
def index(): def index():
https_redirect="<script src=\"https://nathan.woodburn/https.js\"></script>"
# Get host from request # Get host from request
host = request.headers.get('host') host = request.headers.get('host')
tld = host.split('.')[-1] tld = host.split('.')[-1]
tld = tld.split(':')[0] tld = tld.split(':')[0]
if tld == 'localhost' or tld == '1': if tld == 'localhost' or tld == '1':
tld = 'example' 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__': if __name__ == '__main__':
app.run(debug=False, port=5000, host='0.0.0.0') app.run(debug=False, port=5000, host='0.0.0.0')

View File

@ -4,7 +4,7 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no"> <meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<title>.tas/ domains</title> <title>.{{tld}}/ domains</title>
<meta name="description" content=".tas/ domains"> <meta name="description" content=".tas/ domains">
<link rel="icon" type="image/png" sizes="1024x1024" href="assets/img/favicon.png"> <link rel="icon" type="image/png" sizes="1024x1024" href="assets/img/favicon.png">
<link rel="icon" type="image/png" sizes="1024x1024" href="assets/img/favicon.png"> <link rel="icon" type="image/png" sizes="1024x1024" href="assets/img/favicon.png">
@ -21,7 +21,7 @@
<div style="display: inline-block;text-align: left;"> <div style="display: inline-block;text-align: left;">
<code><span>this_page</span>.<em>not_found</em> = true;</code> <code><span>this_page</span>.<em>not_found</em> = true;</code>
<code><span>if</span> (<b>you_spelt_it_wrong</b>){<br><span>autocorrect</span>.<em>enable</em>();<br>}</code> <code><span>if</span> (<b>you_spelt_it_wrong</b>){<br><span>autocorrect</span>.<em>enable</em>();<br>}</code>
<code><span>else if</span> (<b>we_screwed_up</b>){<br><em>alert</em>(<i>"Strewth mate, you're lost! Fair dinkum, why are you here?"</i>);<br><span>window</span>.<em>location</em> = home;<br>}</code> <code><span>else if</span> (!<em>exists</em>(<b>location</b>)){<br><em>alert</em>(<i>"You're lost! I'll send you back home"</i>);<br><span>window</span>.<em>location</em> = home;<br>}</code>
</div> </div>
</div> </div>
@ -30,14 +30,13 @@
<script type="text/javascript"> <script type="text/javascript">
function callback(){ function callback(){
return function(){ return function(){
alert("Strewth mate, you're lost! Fair dinkum, why are you here?"); alert("You're lost! I'll send you back home");
window.location = '/'; window.location = '/';
} }
} }
var a = "world"; var a = "world";
setTimeout(callback(), 5000); setTimeout(callback(), 5000);
</script> </script>
<script src="assets/bootstrap/js/bootstrap.min.js"></script> <script src="assets/bootstrap/js/bootstrap.min.js"></script>
<script src="assets/js/404.js"></script> <script src="assets/js/404.js"></script>

View File

@ -46,7 +46,7 @@
<a href="https://nathan.woodburn.au" target="_blank">Nathan.Woodburn/</a> <a href="https://nathan.woodburn.au" target="_blank">Nathan.Woodburn/</a>
</span> </span>
</footer> </footer>
<script src="https://nathan.woodburn/https.js"></script> {{https_redirect | safe}}
<script src="assets/bootstrap/js/bootstrap.min.js"></script> <script src="assets/bootstrap/js/bootstrap.min.js"></script>
</body> </body>