Skip to Content

SyncServer

Create and configure a Gluonic sync server.

Import

import { SyncServer } from '@gluonic/server'

Signature

function SyncServer(config: SyncServerConfig): SyncServerInstance

Parameters

config: SyncServerConfig

PropertyTypeRequiredDescription
databaseDatabaseAdapterYesDatabase adapter instance
authAuthFunctionYesAuthentication function
appFastifyInstanceNoExisting Fastify app (creates new if omitted)
basePathstringNoBase path for sync routes (default: /sync/v1)
broadcasterBroadcasterNoRedis broadcaster for multi-pod sync
snapshotsSnapshotConfigNoSnapshot caching configuration
maxDeltanumberNoMax sync actions per delta request (default: 5000)
retentionDaysnumberNoDays to retain sync actions (default: indefinite)

Returns

SyncServerInstance

PropertyTypeDescription
listen()Promise<void>Start the server
close()Promise<void>Stop the server
appFastifyInstanceUnderlying 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

Last updated on