I am writing a simple web app using Flask for backend and Vue for the client side. I have the following folder structure:
.
├── client/
│ ├── dist/
│ │ ├── css/
│ │ ├── js/
│ │ └── index.html
│ └── ... (Vue folder structure)
│
└── server/
└── server.py
This is how my flask server looks like (supposed to serve the compiled Vue app statically):
from flask import Flask
app = Flask(__name__, static_folder='../client/dist')
@app.route('/', defaults={'path': ''})
@app.route('/<path:path>')
def catch_all(path):
return app.send_static_file('index.html')
if __name__ == '__main__':
app.run(host='localhost', port=8000, debug=True)
So the weird part is that if I run python -m http.server
from within client/dist
, it just works fine (and so does yarn serve
when using the development server by Vue). But when I run the Flask app with python server/server.py
, I get the following error in Chrome:
Uncaught SyntaxError: Unexpected token '<' (at chunk-vendors.47da3172.js:1:1)
and same for all Vue generated bundles. On the server side I see that the scripts were actually loaded properly (status code 200). How can I serve the Vue app statically with Flask so that it is actually rendered?