-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
23 lines (19 loc) · 771 Bytes
/
Copy pathapp.py
File metadata and controls
23 lines (19 loc) · 771 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from flask import Flask, send_from_directory, Response
import mimetypes
import os
# Ensure Flask knows about .js MIME type
mimetypes.add_type('application/javascript', '.js')
app = Flask(__name__, static_folder='dist', static_url_path='/')
@app.route('/', defaults={'path': ''})
@app.route('/<path:path>')
def serve(path):
if path != "" and os.path.exists(os.path.join(app.static_folder, path)):
full_path = os.path.join(app.static_folder, path)
mime_type, _ = mimetypes.guess_type(full_path)
with open(full_path, 'rb') as f:
content = f.read()
return Response(content, mimetype=mime_type)
else:
return send_from_directory(app.static_folder, 'index.html')
if __name__ == "__main__":
app.run(debug=True)