Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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"
}
}
48 changes: 48 additions & 0 deletions examples/server.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// 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,
refreshIntervalInMs: 5_000
}
});

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

import express from "express";

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

server.use(express.json());

// Use a middleware to achieve request-driven configuration refresh
server.use((req, res, next) => {
// this call s not blocking, the configuration will be updated asynchronously
appConfig.refresh();
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) ?? "");
});

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