Files
hnsau/server.py
Nathan Woodburn aa21e9f203
All checks were successful
Build Docker / Build Image (push) Successful in 40s
feat: Update home page
2024-02-11 20:00:47 +11:00

75 lines
1.9 KiB
Python

from flask import Flask, make_response, redirect, request, jsonify, render_template, send_from_directory
import os
import dotenv
import requests
import datetime
app = Flask(__name__)
dotenv.load_dotenv()
#Assets routes
@app.route('/assets/<path:path>')
def send_report(path):
return send_from_directory('templates/assets', path)
@app.route('/sitemap')
@app.route('/sitemap.xml')
def sitemap():
# Remove all .html from sitemap
with open('templates/sitemap.xml') as file:
sitemap = file.read()
sitemap = sitemap.replace('.html', '')
return make_response(sitemap, 200, {'Content-Type': 'application/xml'})
@app.route('/favicon.png')
def faviconPNG():
return send_from_directory('templates/assets/img', 'favicon.png')
@app.route('/https.js')
@app.route('/handshake.js')
@app.route('/redirect.js')
def handshake():
# return request.path
return send_from_directory('templates/', request.path.split('/')[-1])
@app.route('/.well-known/wallets/<path:path>')
def wallet(path):
return send_from_directory('templates/.well-known/wallets', path, mimetype='text/plain')
# Special routes
@app.route('/email')
def email():
return redirect('mailto:hns@hns.au')
# Main routes
@app.route('/')
def index():
year = datetime.datetime.now().year
return render_template('index.html',year=year)
@app.route('/<path:path>')
def catch_all(path):
year = datetime.datetime.now().year
# If file exists, load it
if os.path.isfile('templates/' + path):
return render_template(path, year=year)
# Try with .html
if os.path.isfile('templates/' + path + '.html'):
return render_template(path + '.html', year=year)
return render_template('404.html'), 404
# 404 catch all
@app.errorhandler(404)
def not_found(e):
return render_template('404.html'), 404
if __name__ == '__main__':
app.run(debug=True, port=5000, host='0.0.0.0')