-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
29 lines (23 loc) · 887 Bytes
/
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
import os
import argparse
from http.server import HTTPServer, SimpleHTTPRequestHandler
def run(
server_class=HTTPServer,
handler_class=SimpleHTTPRequestHandler,
port=8888,
directory=None,
):
if directory: # Change the current working directory if directory is specified
os.chdir(directory)
server_address = ("", port)
httpd = server_class(server_address, handler_class)
print(f"Serving HTTP on http://localhost:{port} from directory '{directory}'...")
httpd.serve_forever()
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="HTTP Server")
parser.add_argument(
"--dir", type=str, help="Directory to serve files from", default="."
)
parser.add_argument("--port", type=int, help="Port to serve HTTP on", default=8888)
args = parser.parse_args()
run(port=args.port, directory=args.dir)