TinyBasePartyKitServerConfig
The TinyBasePartyKitServerConfig
type describes the configuration of a PartyKit Persister
on the server side.
{
storePath?: string;
messagePrefix?: string;
storagePrefix?: string;
responseHeaders?: HeadersInit;
}
Type | Description | |
---|---|---|
storePath? | string | The path used to set and get the whole |
messagePrefix? | string | The prefix at the beginning of the web socket messages between the client and the server when synchronizing the |
storagePrefix? | string | The prefix used before all the keys in the server's durable storage. Use this in case you are worried about the |
responseHeaders? | HeadersInit | An object containing the extra HTTP(S) headers returned to the client from this server. This defaults to the following three headers to allow CORS. |
The defaults (if used on both the server and client) will work fine, but if you are building more complex PartyKit apps and you need to configure path names, for example, then this is the type to use.
Example
When set as the config in a TinyBasePartyKitServer
, this TinyBasePartyKitServerConfig
will expect clients to load and save their JSON serialization from and to an end point in the room called /my_tinybase
. Note that this would require you to also add the matching storePath setting to the PartyKitPersisterConfig
on the client side.
It will also store the data in the durable storage with a prefix of 'tinybase_' in case you are worried about colliding with other data stored in the room.
import {TinyBasePartyKitServer} from 'tinybase/persisters/persister-partykit-server';
export class MyServer extends TinyBasePartyKitServer {
readonly config = {
storePath: '/my_tinybase',
storagePrefix: 'tinybase_',
};
}
Since
v4.3.9