-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathserver.mjs
More file actions
43 lines (33 loc) · 1001 Bytes
/
server.mjs
File metadata and controls
43 lines (33 loc) · 1001 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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}`);
});