You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
title: Azure SignalR Service serverless quickstart - Javascript
2
+
title: Azure SignalR Service serverless quickstart - JavaScript
3
3
description: A quickstart for using Azure SignalR Service and Azure Functions to create an App showing GitHub star count using JavaScript.
4
4
author: vicancy
5
5
ms.author: lianwei
6
-
ms.date: 12/15/2022
6
+
ms.date: 04/19/2023
7
7
ms.topic: quickstart
8
8
ms.service: signalr
9
9
ms.devlang: javascript
10
10
ms.custom: devx-track-js, mode-api
11
11
---
12
-
# Quickstart: Create a serverless app with Azure Functions and SignalR Service using Javascript
12
+
# Quickstart: Create a serverless app with Azure Functions and SignalR Service using JavaScript
13
13
14
-
In this article, you'll use Azure SignalR Service, Azure Functions, and JavaScript to build a serverless application to broadcast messages to clients.
15
-
16
-
> [!NOTE]
17
-
> You can get all code used in the article from [GitHub](https://github.com/aspnet/AzureSignalR-samples/tree/main/samples/QuickStartServerless/javascript).
14
+
In this article, you use Azure SignalR Service, Azure Functions, and JavaScript to build a serverless application to broadcast messages to clients.
18
15
19
16
## Prerequisites
20
17
@@ -23,11 +20,11 @@ This quickstart can be run on macOS, Windows, or Linux.
23
20
| Prerequisite | Description |
24
21
| --- | --- |
25
22
| An Azure subscription |If you don't have a subscription, create an [Azure free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F)|
26
-
| A code editor | You'll need a code editor such as [Visual Studio Code](https://code.visualstudio.com/). |
27
-
|[Azure Functions Core Tools](https://github.com/Azure/azure-functions-core-tools#installing)| Requires version 2.7.1505 or higher to run Python Azure Function apps locally.|
28
-
|[Node.js](https://nodejs.org/en/download/)| See supported node.js versions in the [Azure Functions JavaScript developer guide](../azure-functions/functions-reference-node.md#node-version).|
29
-
|[Azurite](../storage/common/storage-use-azurite.md)| SignalR binding needs Azure Storage. You can use a local storage emulator when a function is running locally. |
30
-
|[Azure CLI](/cli/azure/install-azure-cli)| Optionally, you can use the Azure CLI to create an Azure SignalR Service instance. |
23
+
| A code editor | You need a code editor such as [Visual Studio Code](https://code.visualstudio.com/). |
24
+
|[Azure Functions Core Tools](https://github.com/Azure/azure-functions-core-tools#installing)| Requires version 4.0.5611 or higher to run Node.js v4 programming model.|
25
+
|[Node.js LTS](https://nodejs.org/en/download/)| See supported node.js versions in the [Azure Functions JavaScript developer guide](../azure-functions/functions-reference-node.md#node-version).|
26
+
|[Azurite](../storage/common/storage-use-azurite.md)| SignalR binding needs Azure Storage. You can use a local storage emulator when a function is running locally. |
27
+
| [Azure CLI](/cli/azure/install-azure-cli)| Optionally, you can use the Azure CLI to create an Azure SignalR Service instance.
31
28
32
29
## Create an Azure SignalR Service instance
33
30
@@ -38,12 +35,11 @@ This quickstart can be run on macOS, Windows, or Linux.
38
35
Make sure you have Azure Functions Core Tools installed.
39
36
40
37
1. Open a command line.
41
-
1. Create project directory and then change to it.
38
+
1. Create project directory and then change into it.
42
39
1. Run the Azure Functions `func init` command to initialize a new project.
@@ -54,7 +50,7 @@ After you initialize a project, you need to create functions. This project requi
54
50
-`negotiate`: Allows a client to get an access token.
55
51
-`broadcast`: Uses a time trigger to periodically broadcast messages to all clients.
56
52
57
-
When you run the `func new` command from the root directory of the project, the Azure Functions Core Tools creates the function source files storing them in a folder with the function name. You'll edit the files as necessary replacing the default code with the app code.
53
+
When you run the `func new` command from the root directory of the project, the Azure Functions Core Tools creates the function source files storing them in a folder with the function name. You edit the files as necessary replacing the default code with the app code.
58
54
59
55
### Create the index function
60
56
@@ -64,52 +60,10 @@ When you run the `func new` command from the root directory of the project, the
64
60
func new -n index -t HttpTrigger
65
61
```
66
62
67
-
1. Edit *index/function.json* and replace the contents with the following json code:
68
-
69
-
```json
70
-
{
71
-
"bindings": [
72
-
{
73
-
"authLevel": "anonymous",
74
-
"type": "httpTrigger",
75
-
"direction": "in",
76
-
"name": "req",
77
-
"methods": [
78
-
"get",
79
-
"post"
80
-
]
81
-
},
82
-
{
83
-
"type": "http",
84
-
"direction": "out",
85
-
"name": "res"
86
-
}
87
-
]
88
-
}
89
-
```
63
+
1. Edit *src/functions/httpTrigger.js* and replace the contents with the following json code:
Azure Functions requires a storage account to work. Choose either of the two following options:
269
105
270
-
### Add the SignalR Service connection string to the function app settings
106
+
* Run the free [Azure Storage Emulator](../storage/common/storage-use-azurite.md).
107
+
* Use the Azure Storage service. This may incur costs if you continue to use it.
108
+
109
+
#### [Local emulation](#tab/storage-azurite)
110
+
111
+
1. Start the Azurite storage emulator:
271
112
272
-
Azure Functions requires a storage account to work. You can install and run the [Azure Storage Emulator](../storage/common/storage-use-azurite.md). **Or** you can update the setting to use your real storage account with the following command:
Run the Azure Function app in the local environment:
299
147
300
148
```bash
301
149
func start
302
150
```
303
151
304
-
> [!NOTE]
305
-
> If you see an errors showing read errors on the blob storage, ensure the 'AzureWebJobsStorage' setting in the *local.settings.json* file is set to `UseDevelopmentStorage=true`.
306
-
307
152
After the Azure Function is running locally, go to `http://localhost:7071/api/index`. The page displays the current star count for the GitHub Azure/azure-signalr repository. When you star or unstar the repository in GitHub, you'll see the refreshed count every few seconds.
308
153
309
-
Having issues? Try the [troubleshooting guide](signalr-howto-troubleshoot-guide.md) or [let us know](https://aka.ms/asrs/qscsharp)
154
+
Having issues? Try the [troubleshooting guide](signalr-howto-troubleshoot-guide.md) or [let us know.](https://aka.ms/asrs/qscsharp)
In this quickstart, you built and ran a real-time serverless application in localhost. Next, learn more about how to bi-directional communicating between clients and Azure Function with SignalR Service.
0 commit comments