-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
46 lines (37 loc) · 1.56 KB
/
app.py
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
39
40
41
42
43
44
45
46
import socket
import configuration
from backend import get_api
from flask import Flask, render_template
app = Flask(__name__, template_folder='.')
### Index page
@app.route('/')
def hello():
my_hostname = socket.gethostname()
# Let's fill this dictionary with the data from the API we need
api_data = {
key: get_api(key) for key in
('metadata', 'colors', 'configuration', 'state', 'redis_detection')
}
# Description to return on the index page
description = [
api_data['configuration'].get('description', 'Unable to reach the backend.'),
# api_data['redis_detection'].get('description', 'Unable to reach the backend.'),
# api_data['metadata'].get('description', 'Unable to reach the backend.')
]
# Transforming the list into an HTML-worthy text
description = '\n\n'.join(description)
# Let's render the template in `index.html` and return it.
return render_template(
'index.html',
description=description,
hostname=api_data['metadata'].get('hostname'),
my_hostname=my_hostname,
hostname_color=api_data['colors'].get('hostname'),
version=api_data['configuration'].get('version'),
version_color=api_data['colors'].get('version'),
state_image_link=api_data['state'].get('image_link'),
state_hits=api_data['state'].get('state_hits'),
state_color=api_data['colors'].get('state'),
)
app.run(host='0.0.0.0', port=configuration.listen_port, debug=True)
print('Hello, this is frontend!') # So we can see it in the `kubectl` logs.