Skip to content

Instantly share code, notes, and snippets.

@velotiotech
Created October 20, 2021 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save velotiotech/6b1acefc9c45a06097ffef0889dddca7 to your computer and use it in GitHub Desktop.
Save velotiotech/6b1acefc9c45a06097ffef0889dddca7 to your computer and use it in GitHub Desktop.
console.log(`Route ${route} - data from ${connectionId}`);
if (!event.body) {
return response;
}
let body = JSON.parse(event.body);
const topic = body.topic;
if (body.type === 'subscribe') {
connection.subscribe({ topic });
console.log(`Client subscribing for topic: ${topic}`);
}
if (body.type === 'message') {
await new Topic(topic).publishMessage({ data: body.message });
console.error(`Published messages to subscribers`);
return response;
}
return response;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment