singlepageapplications.rst
This file
Path
docs/patterns/singlepageapplications.rst
24 lines · 731 bytes
Last changed by
Not known.
History of this fileTake it
The walk stopped after 200 commits: lines older than 73739a2 point at it.
Merge branch '2.2.x'David Lordbefore adoption73739a2
lines 1–24why, one step back1Single-Page Applications2========================34Flask can be used to serve Single-Page Applications (SPA) by placing static5files produced by your frontend framework in a subfolder inside of your6project. You will also need to create a catch-all endpoint that routes all7requests to your SPA.89The following example demonstrates how to serve an SPA along with an API::1011 from flask import Flask, jsonify1213 app = Flask(__name__, static_folder='app', static_url_path="/app")141516 @app.route("/heartbeat")17 def heartbeat():18 return jsonify({"status": "healthy"})192021 @app.route('/', defaults={'path': ''})22 @app.route('/<path:path>')23 def catch_all(path):24 return app.send_static_file("index.html")