Providers

External Providers

Last updated by
Harlan Wilton
in feat: third-party adapters (#5).

External providers (adapters) allow you to use third-party WebSocket services for real-time update notifications. This enables instant updates on any platform, including static/prerendered sites.

Why Use External Providers?

  • Static Sites: Get real-time updates without a server
  • Scalability: Offload connection management to dedicated infrastructure
  • Reliability: Leverage battle-tested WebSocket services
  • Simplicity: No server-side WebSocket setup required

Available Adapters

AdapterServiceFree Tier
Pusherpusher.com200k messages/day
Ablyably.com6M messages/month

Pusher

Pusher Channels is a hosted WebSocket service.

npx nypm add pusher-js

Configuration

nuxt.config.ts
import { pusherAdapter } from 'nuxt-skew-protection/adapters/pusher'

export default defineNuxtConfig({
  skewProtection: {
    updateStrategy: pusherAdapter({
      // Required
      key: process.env.PUSHER_KEY,
      cluster: process.env.PUSHER_CLUSTER,
      appId: process.env.PUSHER_APP_ID,
      secret: process.env.PUSHER_SECRET,
      // Optional
      channel: 'skew-protection', // default
      event: 'VersionUpdated', // default
    })
  }
})

Ably

Ably is a realtime messaging platform.

npx nypm add ably

Configuration

nuxt.config.ts
import { ablyAdapter } from 'nuxt-skew-protection/adapters/ably'

export default defineNuxtConfig({
  skewProtection: {
    updateStrategy: ablyAdapter({
      // Required
      key: process.env.ABLY_KEY,
      // Optional
      channel: 'skew-protection', // default
      event: 'VersionUpdated', // default
    })
  }
})

Custom Adapters

Create your own adapter by implementing the SkewAdapter interface:

my-adapter.ts
import type { SkewAdapter } from 'nuxt-skew-protection/adapters'
import { z } from 'zod'

const schema = z.object({
  apiKey: z.string(),
})

export function myAdapter(config: z.infer<typeof schema>): SkewAdapter {
  return {
    name: 'my-adapter',
    config,
    schema,
    subscribe: (onMessage) => {
    // Connect to your WebSocket service
    // Call onMessage({ version }) when update received
      return () => { /* cleanup */ }
    },
    broadcast: async (version) => {
    // Broadcast version to all connected clients
    },
  }
}
Did this page help you?