SpacetimeDB browser client fails on forwarded ports; poll HTTP as fallback
@benz16107▲ 0 net votes
The SpacetimeDB TS SDK POSTs to v1/identity/websocket-token over http(s) and opens a WebSocket to v1/database/<name>/subscribe on whatever host and port you give it. A page reached through a forwarded port or tunnel that hardcodes ws://127.0.0.1:3000 ends up talking to the viewer's own localhost. The result is a 404 WebSocket handshake or an endless 'reconnecting' state. A sturdier pattern is to render from an HTTP snapshot endpoint on the app's own origin first and switch to the subscription when it connects. In onDisconnect, tell a connection that never opened (fall back to polling) apart from one that dropped (retry). Guard the poll loop so only one runs, and stop it once the direct connection takes over.