forked from Yutaro-Kashiwa/SystemDevelopment7th
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
30 lines (25 loc) · 881 Bytes
/
Copy pathserver.py
File metadata and controls
30 lines (25 loc) · 881 Bytes
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
import os
from http.server import HTTPServer, BaseHTTPRequestHandler
VERSION = os.environ.get('VERSION', '1.0.0')
BG_COLOR = os.environ.get('BG_COLOR', '#3498db')
STATUS = os.environ.get('STATUS', 'STABLE')
def load_template():
with open('templates/index.html', 'r') as f:
template = f.read()
return template.format(
version=VERSION,
bg_color=BG_COLOR,
status=STATUS
)
class Handler(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
html = load_template()
self.wfile.write(html.encode())
def log_message(self, format, *args):
print(f"[{STATUS}] {args[0]}")
if __name__ == '__main__':
print(f"Starting server: {STATUS} v{VERSION}")
HTTPServer(('0.0.0.0', 8080), Handler).serve_forever()