-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebserver.py
More file actions
38 lines (26 loc) · 1.03 KB
/
Copy pathwebserver.py
File metadata and controls
38 lines (26 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from flask import Flask, send_from_directory
import random
app = Flask(__name__)
# #########################################################
# # Define routes for all requests to the server for data.
# #########################################################
# Sample JSON route for random array of data.
@app.route('/test')
def test():
# Create a list of 10 random integers.
randvals = [random.randint(1, 500) for x in range(8)]
# Return as a dictionary, which flask auto-converts to json
return {'data': randvals}
# #########################################################
# # Define routes for Svelte app
# #########################################################
# The default path, leads to our for our main Svelte page
@app.route("/")
def base():
return send_from_directory('webapp/public', 'index.html')
# Paths for all the static files (compiled JS/CSS, images, etc.)
@app.route("/<path:path>")
def home(path):
return send_from_directory('webapp/public', path)
if __name__ == "__main__":
app.run(debug=True)