Source code for server.views_main.root

from flask import Blueprint, current_app, request, render_template, send_from_directory
from flask.json import jsonify

bp = Blueprint("root", __name__)

[docs] def serve_index_if_not_proxy(): if current_app.config.get("BEHIND_PROXY") is None: return render_template("index.html") else: return 'The BEHIND_PROXY variable was set. Static files are not served.'
[docs] @bp.route("/") def index(): return serve_index_if_not_proxy()
[docs] @bp.route("/<path:path>") def index_fallback(path): # Unhandled API requests to /auth, /api, etc. should not be silent for prefix in ("auth", "api"): if path.startswith(prefix): return jsonify(errors={"error": f"Unknown /{prefix} endpoint."}), 404 # Otherwise let the frontend handle it return serve_index_if_not_proxy()
[docs] @bp.route("/robots.txt") @bp.route("/manifest.json") @bp.route("/asset-manifest.json") def static_from_root(): return send_from_directory(current_app.template_folder, request.path[1:])