Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions examples/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"dependencies": {
"@azure/app-configuration-provider": "latest",
"@azure/app-configuration-provider": "2.0.0-preview.2",
"@azure/identity": "^4.1.0",
"dotenv": "^16.3.1"
"dotenv": "^16.3.1",
"express": "^4.21.2"
}
}
43 changes: 43 additions & 0 deletions examples/server.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import * as dotenv from "dotenv";
dotenv.config()

import { load } from "@azure/app-configuration-provider";
const connectionString = process.env.APPCONFIG_CONNECTION_STRING;
const appConfig = await load(connectionString, {
refreshOptions: {
enabled: true
}
});

appConfig.onRefresh(() => {
console.log("Configuration has been refreshed.");
});

import express from "express";

const app = express();
const PORT = 3000;

app.use(express.json());

app.get("/", (req, res) => {
appConfig.refresh();
res.send("Please go to /config to get the configuration.");
});

app.get("/config", (req, res) => {
appConfig.refresh();
res.json(appConfig.constructConfigurationObject());
});

app.get("/config/:key", (req, res) => {
appConfig.refresh();
res.json(appConfig.get(req.params.key) ?? "");
});

app.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`);
});
Loading