Skip to content

Commit

Permalink
Merge pull request #90352 from Faless/web/serve_fix_browser_order
Browse files Browse the repository at this point in the history
[Web] Fix browser opening too early with `serve.py`
  • Loading branch information
akien-mga committed Aug 19, 2024
2 parents 3a4e0f1 + 470a358 commit d142413
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions platform/web/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import socket
import subprocess
import sys
from http.server import HTTPServer, SimpleHTTPRequestHandler, test # type: ignore
from http.server import HTTPServer, SimpleHTTPRequestHandler
from pathlib import Path


Expand Down Expand Up @@ -38,12 +38,24 @@ def shell_open(url):
def serve(root, port, run_browser):
os.chdir(root)

address = ("", port)
httpd = DualStackServer(address, CORSRequestHandler)

url = f"http://127.0.0.1:{port}"
if run_browser:
# Open the served page in the user's default browser.
print("Opening the served URL in the default browser (use `--no-browser` or `-n` to disable this).")
shell_open(f"http://127.0.0.1:{port}")
print(f"Opening the served URL in the default browser (use `--no-browser` or `-n` to disable this): {url}")
shell_open(url)
else:
print(f"Serving at: {url}")

test(CORSRequestHandler, DualStackServer, port=port)
try:
httpd.serve_forever()
except KeyboardInterrupt:
print("\nKeyboard interrupt received, stopping server.")
finally:
# Clean-up server
httpd.server_close()


if __name__ == "__main__":
Expand Down

0 comments on commit d142413

Please sign in to comment.