TinyBase logoTinyBase

TinyBasePartyKitServerConfig

{
  storePath?: string;
  messagePrefix?: string;
  storagePrefix?: string;
  responseHeaders?: HeadersInit;
}
TypeDescription
storePath?string

The path used to set and get the whole Store over HTTP(S) on the server. This must match the storePath property of the PartyKitPersisterConfig used on the client. Both default to '/store'.

messagePrefix?string

The prefix at the beginning of the web socket messages between the client and the server when synchronizing the Store. Use this to make sure they do not collide with any other message syntax that your room is using. This must match the messagePrefix property of the PartyKitPersisterConfig object used on the client. Both default to an empty string.

storagePrefix?string

The prefix used before all the keys in the server's durable storage. Use this in case you are worried about the Store data colliding with other data stored in the room. Defaults to an empty string.

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:

Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: *
Access-Control-Allow-Headers: *

If you set this field, it will override the default completely. So, for example, if you add another header but still want the CORS defaults, you will need to explicitly set the Access-Control-Allow headers above again.

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.

class MyServer extends TinyBasePartyKitServer {
  readonly config = {
    storePath: '/my_tinybase',
    storagePrefix: 'tinybase_',
  };
}

Since

v4.3.9