-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
35 lines (32 loc) · 1.07 KB
/
server.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
# server.py
import os
from http.server import BaseHTTPRequestHandler, HTTPServer
import json
class RequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
env_vars = {key: value for key, value in os.environ.items()}
html = f"""
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Environment Variables</title>
</head>
<body>
<h1>Environment Variables v4.0</h1>
<pre>{json.dumps(env_vars, indent=4)}</pre>
</body>
</html>
"""
self.wfile.write(html.encode('utf-8'))
def run(server_class=HTTPServer, handler_class=RequestHandler, port=8000):
server_address = ('', port)
httpd = server_class(server_address, handler_class)
print(f'Starting server on port {port}...')
httpd.serve_forever()
if __name__ == '__main__':
run()