mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2024-12-22 11:56:49 +01:00
Ported: [Web] Add the "serve" and "run" scons targets.
You can now run the test HTTP server by calling:
scons p=javascript serve
If you also wish to run the browser, call instead:
scons p=javascript 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.
- Faless
eda014197f
This commit is contained in:
parent
91e598aa7b
commit
b6252e8d3a
@ -2,6 +2,21 @@
|
||||
|
||||
Import("env")
|
||||
|
||||
# The HTTP server "targets". Run with "scons p=javascript serve", or "scons p=javascript run"
|
||||
if "serve" in COMMAND_LINE_TARGETS or "run" in COMMAND_LINE_TARGETS:
|
||||
from serve import serve
|
||||
import os
|
||||
|
||||
port = os.environ.get("PANDEMONIUM_WEB_TEST_PORT", 8060)
|
||||
try:
|
||||
port = int(port)
|
||||
except Exception:
|
||||
print("PANDEMONIUM_WEB_TEST_PORT must be a valid integer")
|
||||
sys.exit(255)
|
||||
serve(env.Dir("#bin/.javascript_zip").abspath, port, "run" in COMMAND_LINE_TARGETS)
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
javascript_files = [
|
||||
"audio_driver_javascript.cpp",
|
||||
"http_client_javascript.cpp",
|
||||
|
@ -23,6 +23,15 @@ def shell_open(url):
|
||||
opener = "open" if sys.platform == "darwin" else "xdg-open"
|
||||
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()
|
||||
@ -41,12 +50,4 @@ if __name__ == "__main__":
|
||||
# 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)
|
Loading…
Reference in New Issue
Block a user