-
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 7 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
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
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
zhiyuanliang-ms marked this conversation as resolved.
Show resolved
Hide resolved
|
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 |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
|
|
||
| import * as dotenv from "dotenv"; | ||
| dotenv.config() | ||
|
|
||
| import { load } from "@azure/app-configuration-provider"; | ||
| import { DefaultAzureCredential } from "@azure/identity"; | ||
| const endpoint = process.env.APPCONFIG_ENDPOINT; | ||
| const credential = new DefaultAzureCredential(); | ||
| const appConfig = await load(endpoint, credential, { | ||
| refreshOptions: { | ||
| enabled: true, | ||
| refreshIntervalInMs: 5_000 | ||
zhiyuanliang-ms marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| }); | ||
|
|
||
| appConfig.onRefresh(() => { | ||
| console.log("Configuration has been refreshed."); | ||
zhiyuanliang-ms marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }); | ||
|
|
||
| import express from "express"; | ||
|
|
||
| const server = express(); | ||
| const PORT = 3000; | ||
|
|
||
| server.use(express.json()); | ||
|
|
||
| // Use a middleware to achieve request-driven configuration refresh | ||
zhiyuanliang-ms marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // For more information, please go to dynamic refresh tutorial: https://learn.microsoft.com/azure/azure-app-configuration/enable-dynamic-configuration-javascript | ||
| server.use((req, res, next) => { | ||
| // this call s not blocking, the configuration will be updated asynchronously | ||
| appConfig.refresh(); | ||
zhiyuanliang-ms marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| next(); | ||
| }); | ||
|
|
||
| server.get("/", (req, res) => { | ||
| res.send("Please go to /config to get the configuration."); | ||
| }); | ||
|
|
||
| server.get("/config", (req, res) => { | ||
| res.json(appConfig.constructConfigurationObject()); | ||
| }); | ||
|
|
||
| server.get("/config/:key", (req, res) => { | ||
| res.json(appConfig.get(req.params.key) ?? ""); | ||
zhiyuanliang-ms marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }); | ||
|
|
||
| server.listen(PORT, () => { | ||
| console.log(`Server is running on http://localhost:${PORT}`); | ||
| }); | ||
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
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.