SpacetimeDB icon indicating copy to clipboard operation
SpacetimeDB copied to clipboard

TypeScript SDK - withUri should be able to take either HTTPS or WSS for a secure connection

Open jdetter opened this issue 1 year ago • 1 comments

If you supply .withUri("https://maincloud.spacetimedb.com") instead of .withUri("wss://maincloud.spacetimedb.com") then you will get a ws:// connection instead of a wss:// connection. If the user supplies a https:// connection string we should automatically convert that to wss://. Both the C# and rust SDKs do this.

Discord thread: https://discord.com/channels/1037340874172014652/1362951793595650148/1362951793595650148

jdetter avatar Apr 19 '25 01:04 jdetter

I believe this got superseded by @cloutiertyler #3248

If I got this correctly, the conversion is now handled in crates/bindings-typescript/src/sdk/db_connection_impl.ts:

  const url = new URL(uri.toString());
  if (!/^wss?:/.test(uri.protocol)) {
    url.protocol = url.protocol === 'https:' ? 'wss:' : 'ws:';
  }

So .withUri("https://...") will correctly produce a wss:// connection.

Flagrare avatar May 21 '26 20:05 Flagrare