diff options
Diffstat (limited to 'web/play/src/main.ts')
| -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) { |
