Skip to content
Myr

singlepageapplications.rst

This file

Path

docs/patterns/singlepageapplications.rst

24 lines · 731 bytes

Last changed by

Not known.

History of this file

Take it

1Single-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")