Skip to content

Commit 34c3f5b

Browse files
committed
[partykit] Fixed protocol handling
1 parent 45c88ab commit 34c3f5b

File tree

4 files changed

+8
-3
lines changed

4 files changed

+8
-3
lines changed

src/persisters/persister-partykit-client.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ import {jsonString} from '../common/json';
1515
type MessageListener = (event: MessageEvent) => void;
1616

1717
const MESSAGE = 'message';
18-
const HTTPS = 'https:';
1918

2019
export const createPartyKitPersister = ((
2120
store: Store,
2221
connection: PartySocket,
22+
storeUrlProtocol: 'http' | 'https' = 'https',
2323
onIgnoredError?: (error: any) => void,
2424
): Persister => {
2525
const {host, room} = connection.partySocketOptions;
2626
const storeUrl =
27-
(location.protocol == HTTPS ? HTTPS : 'http:') +
28-
'//' +
27+
storeUrlProtocol +
28+
'://' +
2929
host +
3030
'/parties/' +
3131
((connection as any).name ?? 'main') +

src/types/docs/persisters/persister-partykit-client.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
* @param store The Store to persist.
4848
* @param connection The PartySocket to use for participating in the PartyKit
4949
* room.
50+
* @param storeUrlProtocol The HTTP protocol to use (in addition to the
51+
* websocket channel). This defaults to 'https' but you may wish to use 'http'
52+
* for local PartyKit development.
5053
* @param onIgnoredError An optional handler for the errors that the Persister
5154
* would otherwise ignore when trying to save or load data. This is suitable for
5255
* debugging persistence issues in a development environment.

src/types/persisters/persister-partykit-client.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ import {Store} from '../store';
88
export function createPartyKitPersister(
99
store: Store,
1010
connection: PartySocket,
11+
storeUrlProtocol?: 'http' | 'https',
1112
onIgnoredError?: (error: any) => void,
1213
): Persister;

src/types/with-schemas/persisters/persister-partykit-client.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ import {Persister} from '../persisters';
88
export function createPartyKitPersister<Schemas extends OptionalSchemas>(
99
store: Store<Schemas>,
1010
connection: PartySocket,
11+
storeUrlProtocol?: 'http' | 'https',
1112
onIgnoredError?: (error: any) => void,
1213
): Persister<Schemas>;

0 commit comments

Comments
 (0)