diff --git a/docs/patterns/index.rst b/docs/patterns/index.rst index 78a66a1d..af5d04f9 100644 --- a/docs/patterns/index.rst +++ b/docs/patterns/index.rst @@ -42,3 +42,4 @@ Snippet Archives `_. requestchecksum celery subclassing + singlepageapplications diff --git a/docs/patterns/singlepageapplications.rst b/docs/patterns/singlepageapplications.rst new file mode 100644 index 00000000..71c04877 --- /dev/null +++ b/docs/patterns/singlepageapplications.rst @@ -0,0 +1,24 @@ +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') + + + @app.route("/heartbeat") + def heartbeat(): + return jsonify({"status": "healthy"}) + + + @app.route('/', defaults={'path': ''}) + @app.route('/') + def catch_all(path): + return app.send_static_file("index.html")