SyncServer
Create and configure a Gluonic sync server.
Import
import { SyncServer } from '@gluonic/server'Signature
function SyncServer(config: SyncServerConfig): SyncServerInstanceParameters
config: SyncServerConfig
| Property | Type | Required | Description |
|---|---|---|---|
database | DatabaseAdapter | Yes | Database adapter instance |
auth | AuthFunction | Yes | Authentication function |
app | FastifyInstance | No | Existing Fastify app (creates new if omitted) |
basePath | string | No | Base path for sync routes (default: /sync/v1) |
broadcaster | Broadcaster | No | Redis broadcaster for multi-pod sync |
snapshots | SnapshotConfig | No | Snapshot caching configuration |
maxDelta | number | No | Max sync actions per delta request (default: 5000) |
retentionDays | number | No | Days to retain sync actions (default: indefinite) |
Returns
SyncServerInstance
| Property | Type | Description |
|---|---|---|
listen() | Promise<void> | Start the server |
close() | Promise<void> | Stop the server |
app | FastifyInstance | Underlying Fastify app |
Examples
Minimal Setup
import { SyncServer } from '@gluonic/server'
import { PrismaAdapter } from '@gluonic/server-prisma'
import { JWTAuth } from '@gluonic/auth-jwt'
const database = PrismaAdapter({ prisma })
const server = SyncServer({
database,
auth: JWTAuth({ secret: process.env.JWT_SECRET })
})
await server.listen({ port: 3000 })With All Features
import { RedisCache } from '@gluonic/caching-redis'
const server = SyncServer({
database: PrismaAdapter({ prisma }),
auth: JWTAuth({ secret: process.env.JWT_SECRET }),
broadcaster: RedisCache({ url: process.env.REDIS_URL }),
snapshots: {
storage: 's3',
bucket: 'my-snapshots',
intervalMinutes: 60
},
maxDelta: 10000,
retentionDays: 30
})With Existing Fastify App
import Fastify from 'fastify'
const app = Fastify()
// Add your custom routes
app.get('/health', () => ({ status: 'ok' }))
// Add sync routes
const server = SyncServer({
app, // Use existing app
database,
auth: JWTAuth({ secret: process.env.JWT_SECRET })
})
await server.listen({ port: 3000 })See Also
- PrismaAdapter - Database adapter
- JWTAuth - Authentication
- Server Setup Guide - Getting started
Last updated on