Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
bind on 0.0.0.0 and show 127.0.0.1 and improve the print message
  • Loading branch information
matrixise committed Mar 18, 2019
commit 9bad8f4dcafc743e7173bebd405eddc1113e0e3b
10 changes: 6 additions & 4 deletions Tools/scripts/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ def app(environ, respond):
path = sys.argv[1]
port = int(sys.argv[2]) if len(sys.argv) > 2 else 8000

# by security, the default interface is the loopback address, 127.0.0.1
httpd = simple_server.make_server('127.0.0.1', port, app)
interface, port = httpd.socket.getsockname()
print("Serving {0} on {1} port {2} (http://{1}:{2}/), control-C to stop".format(path, interface, port))
httpd = simple_server.make_server('', port, app)

message = "Serving {0} on {1} port {3} (http://{2}:{3}/), control-C to stop"
parameters = (path, "0.0.0.0", "127.0.0.1", port)

print(message.format(*parameters))
try:
httpd.serve_forever()
except KeyboardInterrupt:
Expand Down