Skip to content

Latest commit

 

History

History
53 lines (39 loc) · 1.23 KB

migrate-from-v1.md

File metadata and controls

53 lines (39 loc) · 1.23 KB

Migrate from v1

Version 1 had a function called createPubSubHandler, which is removed in version 2. This function gave a full-working fastify instance, which is now available as the function createPubSubServer.

Before

import { createPubSubHandler, PubSubHandler } from 'pubsub-http-handler';

interface MyHandler {
  hello: string;
  world: string;
}

const server = async () => {
  const handler: PubSubHandler<MyHandler> = ({ message, data }) => {
    // `message` contains attributes, data (as string), messageId
    // `data` contains a base64 decoded JSON serialized object (type is MyHandler in the example)

    ...
  };

  const { listen } = createPubSubHandler(handler);
  await listen();
};

After

import { createPubSubServer, PubSubHandler } from 'pubsub-http-handler';

interface MyHandler {
  hello: string;
  world: string;
}

const server = async () => {
  const handler: PubSubHandler<MyHandler> = ({ message, data }) => {
    // `message` contains attributes, data (as string), messageId
    // `data` contains a base64 decoded JSON serialized object (type is MyHandler in the example)

    ...
  };

  const { listen } = createPubSubServer(handler);
  await listen();
};

Good luck!