Skip to content

Commit 46e6896

Browse files
Fix so spacetimedb can be hosted with a pathname (#183)
* Allow spacetimedb sdk to work when spacetimedb url is more than a host name. * run pnpm format --------- Co-authored-by: DeveloperChaseLewis <[email protected]>
1 parent 46e3fbd commit 46e6896

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

examples/quickstart-chat/src/index.css

+5-5
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,16 @@ body,
3232
}
3333

3434
body {
35-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
36-
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
37-
sans-serif;
35+
font-family:
36+
-apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu',
37+
'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
3838
-webkit-font-smoothing: antialiased;
3939
-moz-osx-font-smoothing: grayscale;
4040
}
4141

4242
code {
43-
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
44-
monospace;
43+
font-family:
44+
source-code-pro, Menlo, Monaco, Consolas, 'Courier New', monospace;
4545
}
4646

4747
/* ----- Buttons ----- */

packages/sdk/src/db_connection_impl.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,7 @@ export class DbConnectionImpl<
194194
}: DbConnectionConfig) {
195195
stdbLogger('info', 'Connecting to SpacetimeDB WS...');
196196

197-
let url = new URL(`v1/database/${nameOrAddress}/subscribe`, uri);
198-
197+
let url = new URL(uri);
199198
if (!/^wss?:/.test(uri.protocol)) {
200199
url.protocol = 'ws:';
201200
}
@@ -219,6 +218,7 @@ export class DbConnectionImpl<
219218

220219
this.wsPromise = createWSFn({
221220
url,
221+
nameOrAddress,
222222
wsProtocol: 'v1.bsatn.spacetimedb',
223223
authToken: token,
224224
compression: compression,

packages/sdk/src/websocket_decompress_adapter.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,15 @@ export class WebsocketDecompressAdapter {
6363

6464
static async createWebSocketFn({
6565
url,
66+
nameOrAddress,
6667
wsProtocol,
6768
authToken,
6869
compression,
6970
lightMode,
7071
}: {
7172
url: URL;
7273
wsProtocol: string;
74+
nameOrAddress: string;
7375
authToken?: string;
7476
compression: 'gzip' | 'none';
7577
lightMode: boolean;
@@ -90,7 +92,7 @@ export class WebsocketDecompressAdapter {
9092

9193
if (authToken) {
9294
headers.set('Authorization', `Bearer ${authToken}`);
93-
const tokenUrl = new URL('/v1/identity/websocket-token', url);
95+
const tokenUrl = new URL('v1/identity/websocket-token', url);
9496
tokenUrl.protocol = url.protocol === 'wss:' ? 'https:' : 'http:';
9597

9698
const response = await fetch(tokenUrl, { method: 'POST', headers });
@@ -103,15 +105,17 @@ export class WebsocketDecompressAdapter {
103105
);
104106
}
105107
}
106-
url.searchParams.set(
108+
109+
const databaseUrl = new URL(`v1/database/${nameOrAddress}/subscribe`, url);
110+
databaseUrl.searchParams.set(
107111
'compression',
108112
compression === 'gzip' ? 'Gzip' : 'None'
109113
);
110114
if (lightMode) {
111-
url.searchParams.set('light', 'true');
115+
databaseUrl.searchParams.set('light', 'true');
112116
}
113117

114-
const ws = new WS(url, wsProtocol);
118+
const ws = new WS(databaseUrl, wsProtocol);
115119

116120
return new WebsocketDecompressAdapter(ws);
117121
}

0 commit comments

Comments
 (0)