WebPubSubEventHandler class
The handler to handle incoming CloudEvents messages
Constructors
Web |
Creates an instance of a WebPubSubEventHandler for handling incoming CloudEvents messages. Example usage:
|
Properties
path | The path this CloudEvents handler listens to |
Methods
get |
Get the middleware to process the CloudEvents requests |
Constructor Details
WebPubSubEventHandler(string, WebPubSubEventHandlerOptions)
Creates an instance of a WebPubSubEventHandler for handling incoming CloudEvents messages.
Example usage:
import express from "express";
import { WebPubSubEventHandler } from "@azure/web-pubsub-express";
const endpoint = "https://xxxx.webpubsubdev.azure.com"
const handler = new WebPubSubEventHandler('chat', {
handleConnect: (req, res) => {
console.log(JSON.stringify(req));
return {};
},
onConnected: req => {
console.log(JSON.stringify(req));
},
handleUserEvent: (req, res) => {
console.log(JSON.stringify(req));
res.success("Hey " + req.data, req.dataType);
};
allowedEndpoints: [ endpoint ]
},
});
new WebPubSubEventHandler(hub: string, options?: WebPubSubEventHandlerOptions)
Parameters
- hub
-
string
The name of the hub to listen to
- options
- WebPubSubEventHandlerOptions
Options to configure the event handler
Property Details
path
The path this CloudEvents handler listens to
path: string
Property Value
string
Method Details
getMiddleware()
Get the middleware to process the CloudEvents requests
function getMiddleware(): RequestHandler
Returns
RequestHandler