-
Notifications
You must be signed in to change notification settings - Fork 4
Add express example #154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add express example #154
Changes from 8 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a26417b
add express example
zhiyuanliang-ms eac3079
update
zhiyuanliang-ms 119a739
use middleware
zhiyuanliang-ms 145dc18
use token credential
zhiyuanliang-ms cdda179
Merge branch 'main' of https://github.com/Azure/AppConfiguration-Java…
zhiyuanliang-ms 4faf4f8
update
zhiyuanliang-ms 7a89580
update
zhiyuanliang-ms 7b07e65
update
zhiyuanliang-ms 9a2e2b4
update
zhiyuanliang-ms 7576036
update
zhiyuanliang-ms dc81200
update
zhiyuanliang-ms 866a747
update
zhiyuanliang-ms e4f73ea
update
zhiyuanliang-ms File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
100 changes: 50 additions & 50 deletions
100
examples/README.md → examples/console-example/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,50 +1,50 @@ | ||
| # Examples for Azure App Configuration JavaScript Provider | ||
| These examples show how to use the JavaScript Provider for Azure App Configuration in some common scenarios. | ||
| ## Prerequisites | ||
| The examples are compatible with [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule). | ||
| You need [an Azure subscription](https://azure.microsoft.com/free/) and the following Azure resources to run the examples: | ||
| - [Azure App Configuration store](https://learn.microsoft.com/en-us/azure/azure-app-configuration/quickstart-azure-app-configuration-create?tabs=azure-portal) | ||
| The examples retrieve credentials to access your App Configuration store from environment variables. | ||
| Alternatively, edit the source code to include the appropriate credentials. | ||
| See each individual example for details on which environment variables/credentials it requires to function. | ||
| ## Add a key-value | ||
| Add the following key-value to the App Configuration store and leave **Label** and **Content Type** with their default values. For more information about how to add key-values to a store using the Azure portal or the CLI, go to [Create a key-value](./quickstart-azure-app-configuration-create.md#create-a-key-value). | ||
| | Key | Value | | ||
| |------------------------|----------------| | ||
| | *app.settings.message* | *Hello World!* | | ||
| ## Setup & Run | ||
| To run the examples using the published version of the package: | ||
| 1. Install the dependencies using `npm`: | ||
| ```bash | ||
| npm install | ||
| ``` | ||
| 2. There are two ways to run the examples using correct credentials: | ||
| - Edit the file `.env.template`, adding the access keys to your App Configuration store. and rename the file from `.env.template` to just `.env`. The examples will read this file automatically. | ||
| - Alternatively, you can set the environment variables to the access keys to your App Configuration store. In this case, setting up the `.env` file is not required. | ||
| ```bash | ||
| npx cross-env APPCONFIG_CONNECTION_STRING="<appconfig connection string>" | ||
| ``` | ||
| 3. Run the examples: | ||
| ```bash | ||
| node helloworld.mjs | ||
| ``` | ||
| You should see the following output: | ||
| ```Output | ||
| Message from Azure App Configuration: Hello World! | ||
| ``` | ||
| # Examples for Azure App Configuration JavaScript Provider | ||
|
|
||
| These examples show how to use the JavaScript Provider for Azure App Configuration in some common scenarios. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| The examples are compatible with [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule). | ||
|
|
||
| You need [an Azure subscription](https://azure.microsoft.com/free/) and the following Azure resources to run the examples: | ||
|
|
||
| - [Azure App Configuration store](https://learn.microsoft.com/en-us/azure/azure-app-configuration/quickstart-azure-app-configuration-create?tabs=azure-portal) | ||
|
|
||
| The examples retrieve credentials to access your App Configuration store from environment variables. | ||
| Alternatively, edit the source code to include the appropriate credentials. | ||
| See each individual example for details on which environment variables/credentials it requires to function. | ||
|
|
||
| ## Add a key-value | ||
| Add the following key-value to the App Configuration store and leave **Label** and **Content Type** with their default values. For more information about how to add key-values to a store using the Azure portal or the CLI, go to [Create a key-value](./quickstart-azure-app-configuration-create.md#create-a-key-value). | ||
|
|
||
| | Key | Value | | ||
| |------------------------|----------------| | ||
| | *app.settings.message* | *Hello World!* | | ||
|
|
||
| ## Setup & Run | ||
|
|
||
| To run the examples using the published version of the package: | ||
|
|
||
| 1. Install the dependencies using `npm`: | ||
|
|
||
| ```bash | ||
| npm install | ||
| ``` | ||
|
|
||
| 2. There are two ways to run the examples using correct credentials: | ||
|
|
||
| - Edit the file `.env.template`, adding the access keys to your App Configuration store. and rename the file from `.env.template` to just `.env`. The examples will read this file automatically. | ||
|
|
||
| - Alternatively, you can set the environment variables to the access keys to your App Configuration store. In this case, setting up the `.env` file is not required. | ||
| ```bash | ||
| npx cross-env APPCONFIG_CONNECTION_STRING="<appconfig connection string>" | ||
| ``` | ||
|
|
||
| 3. Run the examples: | ||
| ```bash | ||
| node helloworld.mjs | ||
| ``` | ||
| You should see the following output: | ||
| ```Output | ||
| Message from Azure App Configuration: Hello World! | ||
| ``` |
90 changes: 45 additions & 45 deletions
90
examples/configObject.mjs → examples/console-example/configObject.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,45 +1,45 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
|
|
||
| import * as dotenv from "dotenv"; | ||
| dotenv.config() | ||
|
|
||
| /** | ||
| * This example demonstrates how to construct a configuration object from settings loaded from Azure App Configuration. | ||
| * If you are using configuration object instead of Map-styled settings, it would minimize the code changes required to use Azure App Configuration in your application. | ||
| * | ||
| * When you import configuration into Azure App Configuration from a local .json file, the keys are automatically flattened with a separator if specified. | ||
| * E.g. if you import the following .json file, specifying the separator as ".": | ||
| * { | ||
| * "app": { | ||
| * "settings": { | ||
| * "message": "Hello, Azure!" | ||
| * } | ||
| * } | ||
| * } | ||
| * | ||
| * In the configuration explorer, the key-values will be: | ||
| * - Key: "app.settings.message", Value: "Hello, Azure!" | ||
| * | ||
| * With the API `constructConfigurationObject`, you can construct a configuration object with the same shape as the original .json file. | ||
| * The separator is used to split the keys and construct the object. | ||
| * The constructed object will be: { app: { settings: { message: "Hello, Azure!" } } } | ||
| * | ||
| * Below environment variables are required for this example: | ||
| * - APPCONFIG_CONNECTION_STRING | ||
| */ | ||
|
|
||
| import { load } from "@azure/app-configuration-provider"; | ||
| const connectionString = process.env.APPCONFIG_CONNECTION_STRING; | ||
| const settings = await load(connectionString, { | ||
| selectors: [{ | ||
| keyFilter: "app.settings.*" | ||
| }] | ||
| }); | ||
|
|
||
| const config = settings.constructConfigurationObject({ | ||
| separator: "." | ||
| }); | ||
|
|
||
| console.log("Constructed object 'config': ", config); | ||
| console.log(`Message from Azure App Configuration: ${config.app.settings.message}`); | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
|
|
||
| import * as dotenv from "dotenv"; | ||
| dotenv.config() | ||
|
|
||
| /** | ||
| * This example demonstrates how to construct a configuration object from settings loaded from Azure App Configuration. | ||
| * If you are using configuration object instead of Map-styled settings, it would minimize the code changes required to use Azure App Configuration in your application. | ||
| * | ||
| * When you import configuration into Azure App Configuration from a local .json file, the keys are automatically flattened with a separator if specified. | ||
| * E.g. if you import the following .json file, specifying the separator as ".": | ||
| * { | ||
| * "app": { | ||
| * "settings": { | ||
| * "message": "Hello, Azure!" | ||
| * } | ||
| * } | ||
| * } | ||
| * | ||
| * In the configuration explorer, the key-values will be: | ||
| * - Key: "app.settings.message", Value: "Hello, Azure!" | ||
| * | ||
| * With the API `constructConfigurationObject`, you can construct a configuration object with the same shape as the original .json file. | ||
| * The separator is used to split the keys and construct the object. | ||
| * The constructed object will be: { app: { settings: { message: "Hello, Azure!" } } } | ||
| * | ||
| * Below environment variables are required for this example: | ||
| * - APPCONFIG_CONNECTION_STRING | ||
| */ | ||
|
|
||
| import { load } from "@azure/app-configuration-provider"; | ||
| const connectionString = process.env.APPCONFIG_CONNECTION_STRING; | ||
| const settings = await load(connectionString, { | ||
| selectors: [{ | ||
| keyFilter: "app.settings.*" | ||
| }] | ||
| }); | ||
|
|
||
| const config = settings.constructConfigurationObject({ | ||
| separator: "." | ||
zhiyuanliang-ms marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }); | ||
|
|
||
| console.log("Constructed object 'config': ", config); | ||
| console.log(`Message from Azure App Configuration: ${config.app.settings.message}`); | ||
50 changes: 25 additions & 25 deletions
50
examples/helloworld.mjs → examples/console-example/helloworld.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,26 +1,26 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
| import * as dotenv from "dotenv"; | ||
| dotenv.config() | ||
| /** | ||
| * This example retrives all settings with key following pattern "app.settings.*", i.e. starting with "app.settings.". | ||
| * With the option `trimKeyPrefixes`, it trims the prefix "app.settings." from keys for simplicity. | ||
| * Value of config "app.settings.message" will be printed. | ||
| * | ||
| * Below environment variables are required for this example: | ||
| * - APPCONFIG_CONNECTION_STRING | ||
| */ | ||
| import { load } from "@azure/app-configuration-provider"; | ||
| const connectionString = process.env.APPCONFIG_CONNECTION_STRING; | ||
| const settings = await load(connectionString, { | ||
| selectors: [{ | ||
| keyFilter: "app.settings.*" | ||
| }], | ||
| trimKeyPrefixes: ["app.settings."] | ||
| }); | ||
| const message = settings.get("message"); | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
|
|
||
| import * as dotenv from "dotenv"; | ||
| dotenv.config() | ||
|
|
||
| /** | ||
| * This example retrives all settings with key following pattern "app.settings.*", i.e. starting with "app.settings.". | ||
| * With the option `trimKeyPrefixes`, it trims the prefix "app.settings." from keys for simplicity. | ||
| * Value of config "app.settings.message" will be printed. | ||
| * | ||
| * Below environment variables are required for this example: | ||
| * - APPCONFIG_CONNECTION_STRING | ||
| */ | ||
|
|
||
| import { load } from "@azure/app-configuration-provider"; | ||
| const connectionString = process.env.APPCONFIG_CONNECTION_STRING; | ||
| const settings = await load(connectionString, { | ||
| selectors: [{ | ||
| keyFilter: "app.settings.*" | ||
| }], | ||
| trimKeyPrefixes: ["app.settings."] | ||
| }); | ||
| const message = settings.get("message"); | ||
|
|
||
| console.log(`Message from Azure App Configuration: ${message}`); |
60 changes: 30 additions & 30 deletions
60
examples/helloworld_aad.mjs → examples/console-example/helloworld_aad.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,31 +1,31 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
| import * as dotenv from "dotenv"; | ||
| dotenv.config() | ||
| /** | ||
| * This example retrives all settings with key following pattern "app.settings.*", i.e. starting with "app.settings.". | ||
| * With the option `trimKeyPrefixes`, it trims the prefix "app.settings." from keys for simplicity. | ||
| * Value of config "app.settings.message" will be printed. | ||
| * | ||
| * Below environment variables are required for this example: | ||
| * - APPCONFIG_ENDPOINT | ||
| * - AZURE_TENANT_ID | ||
| * - AZURE_CLIENT_ID | ||
| * - AZURE_CLIENT_SECRET | ||
| */ | ||
| import { load } from "@azure/app-configuration-provider"; | ||
| import { getDefaultAzureCredential } from "@azure/identity"; | ||
| const endpoint = process.env.APPCONFIG_ENDPOINT; | ||
| const credential = getDefaultAzureCredential(); | ||
| const settings = await load(endpoint, credential, { | ||
| selectors: [{ | ||
| keyFilter: "app.settings.*" | ||
| }], | ||
| trimKeyPrefixes: ["app.settings."] | ||
| }); | ||
| const message = settings.get("message"); | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
|
|
||
| import * as dotenv from "dotenv"; | ||
| dotenv.config() | ||
|
|
||
| /** | ||
| * This example retrives all settings with key following pattern "app.settings.*", i.e. starting with "app.settings.". | ||
| * With the option `trimKeyPrefixes`, it trims the prefix "app.settings." from keys for simplicity. | ||
| * Value of config "app.settings.message" will be printed. | ||
| * | ||
| * Below environment variables are required for this example: | ||
| * - APPCONFIG_ENDPOINT | ||
| * - AZURE_TENANT_ID | ||
| * - AZURE_CLIENT_ID | ||
| * - AZURE_CLIENT_SECRET | ||
| */ | ||
|
|
||
| import { load } from "@azure/app-configuration-provider"; | ||
| import { getDefaultAzureCredential } from "@azure/identity"; | ||
| const endpoint = process.env.APPCONFIG_ENDPOINT; | ||
| const credential = getDefaultAzureCredential(); | ||
| const settings = await load(endpoint, credential, { | ||
| selectors: [{ | ||
| keyFilter: "app.settings.*" | ||
| }], | ||
| trimKeyPrefixes: ["app.settings."] | ||
| }); | ||
| const message = settings.get("message"); | ||
|
|
||
| console.log(`Message from Azure App Configuration: ${message}`); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.