-
-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathrunserver.py
More file actions
executable file
·48 lines (39 loc) · 1.22 KB
/
runserver.py
File metadata and controls
executable file
·48 lines (39 loc) · 1.22 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
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python3
import http.server
import argparse
from dotenv import load_dotenv
import os
load_dotenv()
DEFAULT_HOST = os.getenv("HOST", "127.0.0.1")
DEFAULT_PORT = int(os.getenv("PORT", 8888))
class Handler(http.server.CGIHTTPRequestHandler):
cgi_directories = ["/cgi-bin"]
def main():
parser = argparse.ArgumentParser(
description="Start a simple CGI-capable web server for serving Perl scripts."
)
parser.add_argument(
"host",
nargs="?",
default=DEFAULT_HOST,
help="Hostname or IP address to bind to (default: %(default)s)"
)
parser.add_argument(
"port",
nargs="?",
type=int,
default=DEFAULT_PORT,
help="Port number to listen on (default: %(default)s)"
)
args = parser.parse_args()
# Use HTTPServer to ensure necessary attributes are present.
with http.server.HTTPServer((args.host, args.port), Handler) as httpd:
print("Collectd-web server running at http://%s:%s/" %
(args.host, args.port))
try:
httpd.serve_forever()
except KeyboardInterrupt:
print("\nShutting down server.")
httpd.server_close()
if __name__ == "__main__":
main()