GitHub 37
Skip to content
ViteHub is still experimental. Expect bugs and breaking changes.

Channels

Receive webhooks with signature checks, dedupe and retry, and send messages from any server code, through one named Channel.

Adapters

One adapter for each Channel. An Agent answers the messages of the Channels that it lists.

Deploys on
  • Node
  • Docker
  • Cloudflare
  • Vercel
server/channels/stripe.ts
import { defineChannel } from 'vite-hub/channels'
import { stripe } from 'vite-hub/channels/adapters'
import { sendQueue } from 'vite-hub/queue'

// The file name makes this the "stripe" Channel.
export default defineChannel({
  // Checks Stripe-Signature with STRIPE_WEBHOOK_SECRET
  adapter: stripe(),
  on: {
    // Runs once per Stripe event ID, after ViteHub stores it.
    // A failed Result retries the event.
    'checkout.session.completed': event =>
      sendQueue('fulfil', event.data),
  },
})
server/channels/stripe.ts

One file for each connection

Add a file to server/channels. Its name is the Channel name for both directions.

Webhooks that run once

ViteHub checks the signature, stores the delivery, drops duplicates by delivery ID, and retries the target.

A target for each event

Send an event to a handler, a Queue, a Workflow, or the Agent that lists the Channel.

Send from anywhere

useChannel(name).send() returns [undefined, receipt] or [error, undefined].

Start a trigger from code

A Schedule starts a Channel trigger with the same delivery rules, without a fake webhook.

Logs without message text

Each send logs when it starts and ends. The logs leave out the message text and options.