diff options
| author | salmonik <salmonik@tuta.io> | 2026-11-08 11:53:04 +0100 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-11-08 11:53:04 +0100 |
| commit | 0bace1ce8826a9a1be4003681fab5138f174c275 (patch) | |
| tree | bd191ef204486c950e8407718cb2ddb1dad64e44 /web/play/src | |
| parent | web: link the GPL source from the play page; normalise gateway config (diff) | |
| download | zagan-bet-0bace1ce8826a9a1be4003681fab5138f174c275.tar.gz zagan-bet-0bace1ce8826a9a1be4003681fab5138f174c275.zip | |
dev: add a no-nginx browser stack script
scripts/dev-web.sh builds the server, gateway and app, creates target/dev-web/identity, and runs the game server, webd and a loopback static server. The app accepts a ?ws= override only on loopback so the page and gateway can sit on different local ports; production stays same-origin at /ws.
Diffstat (limited to '')
| -rw-r--r-- | web/play/src/main.ts | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/web/play/src/main.ts b/web/play/src/main.ts index 15eecf5..690d827 100644 --- a/web/play/src/main.ts +++ b/web/play/src/main.ts | |||
| @@ -63,7 +63,20 @@ const descriptions: Record<string, string> = { | |||
| 63 | const basePath = location.pathname.includes("/play/") | 63 | const basePath = location.pathname.includes("/play/") |
| 64 | ? location.pathname.slice(0, location.pathname.indexOf("/play/")) | 64 | ? location.pathname.slice(0, location.pathname.indexOf("/play/")) |
| 65 | : ""; | 65 | : ""; |
| 66 | const wsUrl = `${location.protocol === "https:" ? "wss" : "ws"}://${location.host}${basePath}/ws`; | 66 | const defaultWsUrl = `${location.protocol === "https:" ? "wss" : "ws"}://${location.host}${basePath}/ws`; |
| 67 | |||
| 68 | // A local-only escape hatch for `scripts/dev-web.sh`, which serves the static | ||
| 69 | // page and the gateway on different loopback ports. Never honour ?ws= on a | ||
| 70 | // real host: it would let a crafted link send a password hash elsewhere. | ||
| 71 | const devWs = new URLSearchParams(location.search).get("ws"); | ||
| 72 | const loopback = | ||
| 73 | location.hostname === "127.0.0.1" || | ||
| 74 | location.hostname === "localhost" || | ||
| 75 | location.hostname === "::1"; | ||
| 76 | const wsUrl = | ||
| 77 | devWs && loopback && (devWs.startsWith("ws://") || devWs.startsWith("wss://")) | ||
| 78 | ? devWs | ||
| 79 | : defaultWsUrl; | ||
| 67 | 80 | ||
| 68 | const gateway = new Gateway(wsUrl, { | 81 | const gateway = new Gateway(wsUrl, { |
| 69 | onHello(hello) { | 82 | onHello(hello) { |
