Server-side API
TeamPlay provides a server-side API for setting up the backend and handling connections. This API is typically used in your server setup code.
createBackend()
Creates a new TeamPlay backend instance.
initConnection(backend, options)
Initializes the connection handler for WebSocket connections.
Parameters
backend: The TeamPlay backend instance created withcreateBackend().options(optional): An object with the following properties:fetchOnly(default:true): If true, server-side subscriptions are not reactive.
Return Value
Returns an object with an upgrade function to be used with a Node.js HTTP server.
Usage Example
Additional Exports
TeamPlay's server module also re-exports some utilities:
ShareDB: The underlying ShareDB library.mongo,mongoClient,createMongoIndex: MongoDB utilities.redis,redlock: Redis utilities.sqlite: SQLite utility.
These can be imported from teamplay/server if needed for advanced configurations.
Notes
- The server-side API is designed to work with Node.js HTTP servers.
- For production use, it's recommended to use MongoDB by setting the
MONGO_URLenvironment variable. - When deploying to a cluster with multiple instances, set the
REDIS_URLenvironment variable for proper scaling.