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
Copy file name to clipboardExpand all lines: articles/azure-app-configuration/enable-dynamic-configuration-javascript.md
+16-12Lines changed: 16 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,13 +3,13 @@ title: Use dynamic configuration in JavaScript
3
3
titleSuffix: Azure App Configuration
4
4
description: Learn how to dynamically update configuration data for JavaScript.
5
5
services: azure-app-configuration
6
-
author: eskibear
6
+
author: zhiyuanliang-ms
7
7
ms.service: azure-app-configuration
8
8
ms.devlang: javascript
9
9
ms.topic: tutorial
10
10
ms.date: 03/27/2024
11
11
ms.custom: devx-track-js
12
-
ms.author: yanzh
12
+
ms.author: zhiyuanliang
13
13
#Customer intent: As a JavaScript developer, I want to dynamically update my app to use the latest configuration data in Azure App Configuration.
14
14
---
15
15
# Tutorial: Use dynamic configuration in JavaScript
@@ -44,8 +44,8 @@ Choose the following instructions based on how your application consumes configu
44
44
### [Use configuration as Map](#tab/configuration-map)
45
45
46
46
```javascript
47
-
// Connecting to Azure App Configuration using connection string
48
-
constsettings=awaitload(connectionString, {
47
+
// Connecting to Azure App Configuration using endpoint and token credential
48
+
constsettings=awaitload(endpoint, credential, {
49
49
// Setting up to refresh when the sentinel key is changed
50
50
refreshOptions: {
51
51
enabled:true,
@@ -60,8 +60,8 @@ Choose the following instructions based on how your application consumes configu
60
60
To ensure an up-to-date configuration, update the configuration object in the `onRefresh` callback triggered whenever a configuration change is detected and the configuration is updated.
61
61
62
62
```javascript
63
-
// Connecting to Azure App Configuration using connection string
64
-
const settings = await load(connectionString, {
63
+
// Connecting to Azure App Configuration using endpoint and token credential
const credential = new DefaultAzureCredential(); // For more information, see https://learn.microsoft.com/azure/developer/javascript/sdk/credential-chains#use-defaultazurecredential-for-flexibility
119
121
120
122
async function run() {
121
-
// Connecting to Azure App Configuration using connection string
122
-
const settings = await load(connectionString, {
123
+
// Connecting to Azure App Configuration using endpoint and token credential
const credential = new DefaultAzureCredential(); // For more information, see https://learn.microsoft.com/azure/developer/javascript/sdk/credential-chains#use-defaultazurecredential-for-flexibility
146
150
147
151
async function run() {
148
-
// Connecting to Azure App Configuration using connection string
149
-
const settings = await load(connectionString, {
152
+
// Connecting to Azure App Configuration using endpoint and token credential
Copy file name to clipboardExpand all lines: articles/azure-app-configuration/quickstart-feature-flag-javascript.md
+74-18Lines changed: 74 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -42,10 +42,54 @@ Add a feature flag called *Beta* to the App Configuration store and leave **Labe
42
42
43
43
1. Create a file named *app.js* and add the following code.
44
44
45
+
### [Microsoft Entra ID (recommended)](#tab/entra-id)
46
+
You use the `DefaultAzureCredential` to authenticate to your App Configuration store. Follow the [instructions](./concept-enable-rbac.md#authentication-with-token-credentials) to assign your credential the **App Configuration Data Reader** role. Be sure to allow sufficient time for the permission to propagate before running your application.
const credential = new DefaultAzureCredential(); // For more information, see https://learn.microsoft.com/azure/developer/javascript/sdk/credential-chains#use-defaultazurecredential-for-flexibility
55
+
56
+
async function run() {
57
+
// Connect to Azure App Configuration using connection string
58
+
const settings = await load(connectionString, {
59
+
featureFlagOptions: {
60
+
enabled: true,
61
+
// Note: selectors must be explicitly provided for feature flags.
62
+
selectors: [{
63
+
keyFilter: "*"
64
+
}],
65
+
refresh: {
66
+
enabled: true,
67
+
refreshIntervalInMs: 10_000
68
+
}
69
+
}
70
+
});
71
+
72
+
// Create a feature flag provider which uses a map as feature flag source
73
+
const ffProvider = new ConfigurationMapFeatureFlagProvider(settings);
74
+
// Create a feature manager which will evaluate the feature flag
75
+
const fm = new FeatureManager(ffProvider);
76
+
77
+
while (true) {
78
+
await settings.refresh(); // Refresh to get the latest feature flag settings
79
+
const isEnabled = await fm.isEnabled("Beta"); // Evaluate the feature flag
@@ -80,42 +124,54 @@ Add a feature flag called *Beta* to the App Configuration store and leave **Labe
80
124
run().catch(console.error);
81
125
```
82
126
127
+
---
128
+
83
129
## Run the application
84
130
85
-
1. Set an environment variable named **AZURE_APPCONFIG_CONNECTION_STRING**, and set it to the connection string of your App Configuration store. At the command line, run the following command:
### [Microsoft Entra ID (recommended)](#tab/entra-id)
134
+
Set the environment variable named **AZURE_APPCONFIG_ENDPOINT** to the endpoint of your App Configuration store found under the *Overview* of your store in the Azure portal.
88
135
89
-
To run the app locally using the Windows command prompt, run the following command and replace `<app-configuration-store-connection-string>` with the connection string of your app configuration store:
136
+
If you use the Windows command prompt, run the following command and restart the command prompt to allow the change to take effect:
If you use Windows PowerShell, run the following command and replace `<app-configuration-store-connection-string>` with the connection string of your app configuration store:
Set the environment variable named **AZURE_APPCONFIG_CONNECTION_STRING** to the read-only connection string of your App Configuration store found under *Access keys* of your store in the Azure portal.
104
156
105
-
If you use macOS, run the following command and replace `<app-configuration-store-connection-string>` with the connection string of your app configuration store:
157
+
If you use the Windows command prompt, run the following command and restart the command prompt to allow the change to take effect:
If you use Linux, run the following command and replace `<app-configuration-store-connection-string>` with the connection string of your app configuration store:
0 commit comments