Skip to content

Commit 85fa61b

Browse files
authored
update
1 parent 4d400a0 commit 85fa61b

File tree

1 file changed

+41
-41
lines changed

1 file changed

+41
-41
lines changed

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

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ In this step-by-step tutorial, you build a chat room with authentication and pri
2424
> [!NOTE]
2525
> You can get the code mentioned in this article from [GitHub](https://github.com/aspnet/AzureSignalR-samples/blob/90523e17ee5fec184a197b143bb5070bc6d4f312/samples/ServerlessChatWithAuth/v4-model/).
2626
27-
# [Isolated process](#tab/isolated-process)
27+
# [Model v3](#tab/nodejs-v3)
2828

2929
> [!NOTE]
3030
> You can get the code mentioned in this article from [GitHub](https://github.com/aspnet/AzureSignalR-samples/blob/90523e17ee5fec184a197b143bb5070bc6d4f312/samples/ServerlessChatWithAuth/v3-model/).
@@ -236,58 +236,58 @@ The web app also requires an HTTP API to send chat messages. Create an HTTP trig
236236
# [Model v4](#tab/nodejs-v4)
237237
1. From the root project folder, create an HTTP trigger function named `sendMessage` from the template by using the following command:
238238
239-
```bash
240-
func new --name sendMessage --template "Http trigger"
241-
```
239+
```bash
240+
func new --name sendMessage --template "Http trigger"
241+
```
242242
243243
1. Open the _src/functions/sendMessage.js_ file, update the content as follows:
244244
245-
```js
246-
const { app, output } = require('@azure/functions');
247-
248-
const signalR = output.generic({
249-
type: 'signalR',
250-
name: 'signalR',
251-
hubName: 'default',
252-
connectionStringSetting: 'AzureSignalRConnectionString',
253-
});
254-
255-
app.http('messages', {
256-
methods: ['POST'],
257-
authLevel: 'anonymous',
258-
extraOutputs: [signalR],
259-
handler: async (request, context) => {
260-
const message = await request.json();
261-
message.sender = request.headers && request.headers.get('x-ms-client-principal-name') || '';
262-
263-
let recipientUserId = '';
264-
if (message.recipient) {
265-
recipientUserId = message.recipient;
266-
message.isPrivate = true;
267-
}
268-
context.extraOutputs.set(signalR,
269-
{
270-
'userId': recipientUserId,
271-
'target': 'newMessage',
272-
'arguments': [message]
273-
});
274-
}
275-
});
276-
```
245+
```js
246+
const { app, output } = require('@azure/functions');
247+
248+
const signalR = output.generic({
249+
type: 'signalR',
250+
name: 'signalR',
251+
hubName: 'default',
252+
connectionStringSetting: 'AzureSignalRConnectionString',
253+
});
254+
255+
app.http('messages', {
256+
methods: ['POST'],
257+
authLevel: 'anonymous',
258+
extraOutputs: [signalR],
259+
handler: async (request, context) => {
260+
const message = await request.json();
261+
message.sender = request.headers && request.headers.get('x-ms-client-principal-name') || '';
262+
263+
let recipientUserId = '';
264+
if (message.recipient) {
265+
recipientUserId = message.recipient;
266+
message.isPrivate = true;
267+
}
268+
context.extraOutputs.set(signalR,
269+
{
270+
'userId': recipientUserId,
271+
'target': 'newMessage',
272+
'arguments': [message]
273+
});
274+
}
275+
});
276+
```
277277
278-
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.
278+
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.
279279
280-
The function can read the sender's identity and can accept a `recipient` value in the message body to allow you to send a message privately to a single user. You'll use these functionalities later in the tutorial.
280+
The function can read the sender's identity and can accept a `recipient` value in the message body to allow you to send a message privately to a single user. You'll use these functionalities later in the tutorial.
281281
282282
1. Save the file.
283283
284284
# [Model v3](#tab/nodejs-v3)
285285
286286
1. From the root project folder, create an HTTP trigger function named `sendMessage` from the template by using the following command:
287287
288-
```bash
289-
func new --name sendMessage --template "Http trigger"
290-
```
288+
```bash
289+
func new --name sendMessage --template "Http trigger"
290+
```
291291
292292
1. To configure bindings for the function, replace the content of _sendMessage/function.json_ with the following code:
293293

0 commit comments

Comments
 (0)