Merge pull request #2996 from alysivji/spa-docs

[Docs] Add Single-Page Web Application pattern
This commit is contained in:
David Lord 2019-01-06 06:26:07 -08:00 committed by GitHub
commit b78ebacca7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 0 deletions

View file

@ -42,3 +42,4 @@ Snippet Archives <http://flask.pocoo.org/snippets/>`_.
requestchecksum
celery
subclassing
singlepageapplications

View file

@ -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('/<path:path>')
def catch_all(path):
return app.send_static_file("index.html")