Skip to content

Commit

Permalink
[Web] Add the "serve" and "run" scons targets.
Browse files Browse the repository at this point in the history
You can now run the test HTTP server by calling:

scons p=web serve

If you also wish to run the browser, call instead:

scons p=web run

The default listen port is 8060, but can be overriden via the env
variable GODOT_WEB_TEST_PORT which must be a valid integer.
  • Loading branch information
Faless committed Oct 12, 2022
1 parent ea47e03 commit a066023
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
14 changes: 14 additions & 0 deletions platform/web/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

Import("env")

# The HTTP server "targets". Run with "scons p=web serve", or "scons p=web run"
if "serve" in COMMAND_LINE_TARGETS or "run" in COMMAND_LINE_TARGETS:
from serve import serve
import os

port = os.environ.get("GODOT_WEB_TEST_PORT", 8060)
try:
port = int(port)
except Exception:
print("GODOT_WEB_TEST_PORT must be a valid integer")
sys.exit(255)
serve(env.Dir("#bin/.web_zip").abspath, port, "run" in COMMAND_LINE_TARGETS)
sys.exit(0)

web_files = [
"audio_driver_web.cpp",
"display_server_web.cpp",
Expand Down
21 changes: 12 additions & 9 deletions platform/web/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ def shell_open(url):
subprocess.call([opener, url])


def serve(root, port, run_browser):
os.chdir(root)

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}")

test(CORSRequestHandler, HTTPServer, port=port)


if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("-p", "--port", help="port to listen on", default=8060, type=int)
Expand All @@ -41,12 +52,4 @@ def shell_open(url):
# so that the script can be run from any location.
os.chdir(Path(__file__).resolve().parent)

if args.root:
os.chdir(args.root)

if args.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:{args.port}")

test(CORSRequestHandler, HTTPServer, port=args.port)
serve(args.root, args.port, args.browser)

0 comments on commit a066023

Please sign in to comment.