Synchronize data to your clients in real time with websockets. Deploy on your own infrastructure!
This library is WIP as I test things to make sure they work, with the goal of achieving near parity with Pusher. Use at your own risk, but if you do run into problems, PRs/issues are welcome :)
To deploy your own Sinkr instance, follow these steps:
- Clone this repository
- Run
pnpm installin the root directory - In Cloudflare, ensure you have a domain you want to deploy to.
- In GitHub, create a new GitHub OAuth app
- Make sure the app has the callback URL set to
<your domain>/api/auth/callback/github - Save your client ID and secret
- Make sure the app has the callback URL set to
- Setup your Cloudflare workers
- Run
cd apps/app-manager - Run
pnpm wrangler loginto authenticate Wrangler - Run
pnpm wrangler d1 create <your-database-name>to create a D1 database. - Copy
wrangler.example.tomlintowrangler.tomland fill out the values with your created bindings for bothapp-manageranddeployment- Both should use the same
D1database binding (ID and name) - Each one should use a separate domain. For example,
apps.example.comandws.example.comforapp-manageranddeployment
- Both should use the same
- Run
pnpm wrangler d1 execute <your-database-name> --file setup.sql --remoteand confirm. - Add the following environment variables to a
.envfile:CLOUDFLARE_ACCOUNT_ID: your Cloudflare account IDCLOUDFLARE_DATABASE_ID: the Database ID of your D1 databasaeCLOUDFLARE_D1_TOKEN: the API token created in step 4
- Update
apps/app-manager/src/server/auth.ts:32to add your own GitHub login as an administrator - Add the following Cloudflare secrets:
- Run
pnpm wrangler secret put AUTH_SECRET - Paste a random, securely generated string of characters. I recommend using
openssl rand -base64 32 - Run
pnpm wrangler secret put AUTH_GITHUB_ID - Paste your GitHub OAuth client ID from the app created in step 3
- Run
pnpm wrangler secret put AUTH_GITHUB_SECRET - Paste your GitHub OAuth client secret from the app created in step 3
- Run
pnpm run deployto deploy your App Manager - Run
cd ../deployment - Run
pnpm run deployto deploy your Websocket manager - Link your app manager and worker to your domain.
- Make sure the subdomain you choose for your app manager matches the url you put into GitHub
- Run
- Install the SDK in your app code
- For TypeScript apps of any kind, simply install
@sinkr/corefrom JSR. - For React apps, install
@sinkr/reactfrom JSR. This also exports@sinkr/coreso installing both is not strictly necessary. - For Python apps of any kind, install
sinkrfrom PyPI
- For TypeScript apps of any kind, simply install
- Done! Start sending and receiving messages!