"Fossies" - the Fresh Open Source Software Archive

Member "flask-1.1.2/docs/patterns/singlepageapplications.rst" (3 Apr 2020, 731 Bytes) of package /linux/www/flask-1.1.2.tar.gz:

As a special service "Fossies" has tried to format the requested source page into HTML format (assuming markdown format). Alternatively you can here view or download the uninterpreted source code file. A member file download can also be achieved by clicking within a package contents listing on the according byte size field. See also the latest Fossies "Diffs" side-by-side code changes report for "singlepageapplications.rst": 1.1.1_vs_1.1.2.

Single-Page Applications

Flask can be used to serve Single-Page Applications (SPA) by placing static files produced by your frontend framework in a subfolder inside of your project. You will also need to create a catch-all endpoint that routes all requests to your SPA.

The following example demonstrates how to serve an SPA along with an API:

from flask import Flask, jsonify

app = Flask(__name__, static_folder='app', static_url_path="/app")

def heartbeat():
    return jsonify({"status": "healthy"})

@app.route('/', defaults={'path': ''})
def catch_all(path):
    return app.send_static_file("index.html")