Skip to content

Commit db51567

Browse files
authored
update
1 parent c3c6802 commit db51567

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

articles/azure-signalr/signalr-tutorial-authenticate-azure-functions.md

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -244,36 +244,36 @@ The web app also requires an HTTP API to send chat messages. Create an HTTP trig
244244
1. Open the _src/functions/sendMessage.js_ file, update the content as follows:
245245
246246
```js
247-
const { app, output } = require('@azure/functions');
248-
249-
const signalR = output.generic({
250-
type: 'signalR',
251-
name: 'signalR',
252-
hubName: 'default',
253-
connectionStringSetting: 'AzureSignalRConnectionString',
254-
});
255-
256-
app.http('messages', {
257-
methods: ['POST'],
258-
authLevel: 'anonymous',
259-
extraOutputs: [signalR],
260-
handler: async (request, context) => {
261-
const message = await request.json();
262-
message.sender = request.headers && request.headers.get('x-ms-client-principal-name') || '';
263-
264-
let recipientUserId = '';
265-
if (message.recipient) {
266-
recipientUserId = message.recipient;
267-
message.isPrivate = true;
268-
}
269-
context.extraOutputs.set(signalR,
270-
{
271-
'userId': recipientUserId,
272-
'target': 'newMessage',
273-
'arguments': [message]
274-
});
275-
}
276-
});
247+
const { app, output } = require('@azure/functions');
248+
249+
const signalR = output.generic({
250+
type: 'signalR',
251+
name: 'signalR',
252+
hubName: 'default',
253+
connectionStringSetting: 'AzureSignalRConnectionString',
254+
});
255+
256+
app.http('messages', {
257+
methods: ['POST'],
258+
authLevel: 'anonymous',
259+
extraOutputs: [signalR],
260+
handler: async (request, context) => {
261+
const message = await request.json();
262+
message.sender = request.headers && request.headers.get('x-ms-client-principal-name') || '';
263+
264+
let recipientUserId = '';
265+
if (message.recipient) {
266+
recipientUserId = message.recipient;
267+
message.isPrivate = true;
268+
}
269+
context.extraOutputs.set(signalR,
270+
{
271+
'userId': recipientUserId,
272+
'target': 'newMessage',
273+
'arguments': [message]
274+
});
275+
}
276+
});
277277
```
278278
279279
The function contains an HTTP trigger and a SignalR output binding. It takes the body from the HTTP request and sends it to clients connected to Azure SignalR Service. It invokes a function named `newMessage` on each client.

0 commit comments

Comments
 (0)