From 0ca90ee7e8bcf861465d427b997049d44fd4d996 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Mon, 14 Jun 2021 19:35:02 -0400 Subject: [PATCH] Add subdirectory handling for zelda3, factorio, and minecraft. Add generic 404 page. --- WebHostLib/__init__.py | 51 ++++++++++++++++++----- WebHostLib/static/styles/404.css | 10 +++++ WebHostLib/templates/404.html | 17 ++++++++ WebHostLib/templates/factorio/index.html | 9 ++++ WebHostLib/templates/minecraft/index.html | 9 ++++ WebHostLib/templates/zelda3/index.html | 9 ++++ 6 files changed, 95 insertions(+), 10 deletions(-) create mode 100644 WebHostLib/static/styles/404.css create mode 100644 WebHostLib/templates/404.html create mode 100644 WebHostLib/templates/factorio/index.html create mode 100644 WebHostLib/templates/minecraft/index.html create mode 100644 WebHostLib/templates/zelda3/index.html diff --git a/WebHostLib/__init__.py b/WebHostLib/__init__.py index dedbe2a1..1d46b884 100644 --- a/WebHostLib/__init__.py +++ b/WebHostLib/__init__.py @@ -3,8 +3,10 @@ import uuid import base64 import socket +import jinja2.exceptions from pony.flask import Pony from flask import Flask, request, redirect, url_for, render_template, Response, session, abort, send_from_directory +from flask import Blueprint from flask_caching import Cache from flask_compress import Compress @@ -74,6 +76,41 @@ def register_session(): session["_id"] = uuid4() # uniquely identify each session without needing a login +@app.errorhandler(404) +@app.errorhandler(jinja2.exceptions.TemplateNotFound) +def page_not_found(err): + return render_template('404.html'), 404 + + +base_page = Blueprint('base_page', __name__, template_folder='templates', url_prefix='/') +zelda_page = Blueprint('zelda_page', __name__, template_folder='templates/zelda3', url_prefix='/zelda3') +factorio_page = Blueprint('factorio_page', __name__, template_folder='templates/factorio', url_prefix='/factorio') +minecraft_page = Blueprint('minecraft_page', __name__, template_folder='templates/minecraft', url_prefix='/minecraft') + + +@app.route('/games') +def games(): + return render_template("games.html") + + +@zelda_page.route('/', defaults={'page': 'index.html'}) +@zelda_page.route('/') +def zelda_pages(page='index.html'): + return render_template(page) + + +@factorio_page.route('/', defaults={'page': 'index.html'}) +@factorio_page.route('/') +def factorio_pages(page='index.html'): + return render_template(page) + + +@minecraft_page.route('/', defaults={'page': 'index.html'}) +@minecraft_page.route('/') +def minecraft_pages(page='index.html'): + return render_template(page) + + @app.route('/tutorial///') def tutorial(game, file, lang): return render_template("tutorial.html", game=game, file=file, lang=lang) @@ -84,21 +121,11 @@ def tutorial_landing(): return render_template("tutorialLanding.html") -@app.route('/player-settings') -def player_settings_simple(): - return render_template("playerSettings.html") - - @app.route('/weighted-settings') def player_settings(): return render_template("weightedSettings.html") -@app.route('/games') -def games(): - return render_template("games.html") - - @app.route('/seed/') def viewSeed(seed: UUID): seed = Seed.get(id=seed) @@ -159,3 +186,7 @@ def favicon(): from WebHostLib.customserver import run_server_process from . import tracker, upload, landing, check, generate, downloads, api # to trigger app routing picking up on it app.register_blueprint(api.api_endpoints) +app.register_blueprint(base_page) +app.register_blueprint(zelda_page) +app.register_blueprint(factorio_page) +app.register_blueprint(minecraft_page) diff --git a/WebHostLib/static/styles/404.css b/WebHostLib/static/styles/404.css new file mode 100644 index 00000000..0c53c6c3 --- /dev/null +++ b/WebHostLib/static/styles/404.css @@ -0,0 +1,10 @@ +#page-not-found{ + width: 40em; + margin-left: auto; + margin-right: auto; + text-align: center; +} + +#page-not-found h1{ + margin-bottom: 0.5rem; +} diff --git a/WebHostLib/templates/404.html b/WebHostLib/templates/404.html new file mode 100644 index 00000000..9d567510 --- /dev/null +++ b/WebHostLib/templates/404.html @@ -0,0 +1,17 @@ +{% extends 'pageWrapper.html' %} +{% import "macros.html" as macros %} + +{% block head %} + Page Not Found (404) + +{% endblock %} + +{% block body %} + {% include 'header/oceanHeader.html' %} +
+

This page is out of logic!

+ The page you're looking for doesn't exist.
+ Click here to return to safety. +
+ {% include 'islandFooter.html' %} +{% endblock %} diff --git a/WebHostLib/templates/factorio/index.html b/WebHostLib/templates/factorio/index.html new file mode 100644 index 00000000..e808d9ab --- /dev/null +++ b/WebHostLib/templates/factorio/index.html @@ -0,0 +1,9 @@ + + + + Factorio + + + Factorio + + diff --git a/WebHostLib/templates/minecraft/index.html b/WebHostLib/templates/minecraft/index.html new file mode 100644 index 00000000..f37dc14f --- /dev/null +++ b/WebHostLib/templates/minecraft/index.html @@ -0,0 +1,9 @@ + + + + Minecraft + + + Minecraft + + diff --git a/WebHostLib/templates/zelda3/index.html b/WebHostLib/templates/zelda3/index.html new file mode 100644 index 00000000..0e0e24a8 --- /dev/null +++ b/WebHostLib/templates/zelda3/index.html @@ -0,0 +1,9 @@ + + + + Link to the Past + + + Link to the Past + +