Kumi
0601a39829
Introduced a development mode toggle for the app, which, when enabled, displays a distinctive warning on every page to inform users they are viewing a development version of the site. This warning is styled for clear visibility. Development mode is toggled with a new `--dev` command line argument or by setting an environment variable. The change aims to prevent confusion between the development and production environments for both developers and early users. - Added new CSS rules for a warning alert style in `base.css`. - Modified `main.py` to check for a development mode flag and pass a warning message to the template if the flag is set. - Updated `base.html` to include the warning message when present. - Added a new template for the development warning message.
53 lines
1.3 KiB
Python
53 lines
1.3 KiB
Python
from flask import Flask, render_template, send_from_directory
|
|
from jinja2 import TemplateNotFound
|
|
|
|
import json
|
|
import pathlib
|
|
import os
|
|
|
|
from argparse import ArgumentParser
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
|
@app.route("/assets/<path:path>")
|
|
def send_assets(path):
|
|
return send_from_directory("assets", path)
|
|
|
|
|
|
@app.route("/", defaults={"path": "index"})
|
|
@app.route("/<path:path>.html")
|
|
def catch_all(path):
|
|
try:
|
|
services = json.loads(
|
|
(pathlib.Path(__file__).parent / "services.json").read_text()
|
|
)
|
|
|
|
warning = None
|
|
|
|
if app.development_mode:
|
|
warning = render_template("prod-warning.html")
|
|
|
|
return render_template(
|
|
f"{path}.html", services=services, warning=warning
|
|
)
|
|
except TemplateNotFound:
|
|
return "404 Not Found", 404
|
|
|
|
|
|
app.development_mode = False
|
|
|
|
if os.environ.get("PRIVATECOFFEE_DEV"):
|
|
app.development_mode = True
|
|
|
|
|
|
if __name__ == "__main__":
|
|
parser = ArgumentParser(description="Run the private.coffee web server.")
|
|
parser.add_argument("--port", type=int, default=9810)
|
|
parser.add_argument("--debug", action="store_true")
|
|
parser.add_argument("--dev", action="store_true")
|
|
args = parser.parse_args()
|
|
|
|
app.development_mode = args.dev or app.development_mode
|
|
|
|
app.run(port=args.port, debug=args.debug)
|