Skip to content
Myr

Add SPA pattern to docs

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Aly Sivji · committed by David Lord · parent 4d37aca · Browse files · 2 files+25 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+25 added−0 removed

  • other:+25 added−0 removed

2 files+25 added−0 removed

modified:docs/patterns/index.rst+1 added
40 unmodified lines
41 methodoverrides42 requestchecksum43 celery44 subclassing45 singlepageapplications
added:docs/patterns/singlepageapplications.rst+24 added
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')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")