66 lines
1.7 KiB
Python
66 lines
1.7 KiB
Python
from flask import Flask, make_response, redirect, request, jsonify, render_template, send_from_directory
|
|
import os
|
|
import dotenv
|
|
import requests
|
|
import CloudFlare
|
|
|
|
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('.well-known/wallets', path, mimetype='text/plain')
|
|
|
|
|
|
|
|
# Main routes
|
|
@app.route('/')
|
|
def index():
|
|
return render_template('index.html')
|
|
|
|
@app.route('/<path:path>')
|
|
def catch_all(path):
|
|
# If file exists, load it
|
|
if os.path.isfile('templates/' + path):
|
|
return render_template(path)
|
|
|
|
# Try with .html
|
|
if os.path.isfile('templates/' + path + '.html'):
|
|
return render_template(path + '.html')
|
|
|
|
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') |