Skip to content

Commit 1e0e34e

Browse files
update
1 parent 7db4c1d commit 1e0e34e

File tree

3 files changed

+12
-67
lines changed

3 files changed

+12
-67
lines changed

examples/express-app/pages/beta.html

Lines changed: 0 additions & 28 deletions
This file was deleted.

examples/express-app/pages/index.html

Lines changed: 0 additions & 28 deletions
This file was deleted.

examples/express-app/server.mjs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import express from "express";
22
import path from "path";
3-
import { fileURLToPath } from "url";
4-
import fs from 'node:fs/promises';
53

64
import { load } from "@azure/app-configuration-provider";
75
const connectionString = "<your-connection-string>";;
@@ -33,31 +31,34 @@ We recommend using Azure App Configuration as the source of feature flags.
3331
const featureProvider = new ConfigurationMapFeatureFlagProvider(appConfig);
3432
const featureManager = new FeatureManager(featureProvider);
3533

36-
const app = express();
34+
const server = express();
3735
const PORT = 3000;
3836

39-
const __filename = fileURLToPath(import.meta.url);
40-
const __dirname = path.dirname(__filename);
37+
// Use a middleware to achieve request-driven configuration refresh
38+
server.use((req, res, next) => {
39+
// this call s not blocking, the configuration will be updated asynchronously
40+
appConfig.refresh();
41+
next();
42+
})
4143

42-
const pageDir = path.join(__dirname, "pages");
4344

44-
app.get("/", (req, res) => {
45+
server.get("/", (req, res) => {
4546
appConfig.refresh();
46-
res.sendFile(path.join(pageDir, "index.html"));
47+
res.send("Hello World!");
4748
});
4849

49-
app.get("/Beta", async (req, res) => {
50+
server.get("/Beta", async (req, res) => {
5051
appConfig.refresh();
5152
const { userId, groups } = req.query;
5253

5354
if (await featureManager.isEnabled("Beta", { userId: userId, groups: groups ? groups.split(",") : [] })) {
54-
res.sendFile(path.join(pageDir, "beta.html"));
55+
res.send("Welcome to the Beta page!");
5556
} else {
5657
res.status(404).send("Page not found");
5758
}
5859
});
5960

6061
// Start the server
61-
app.listen(PORT, () => {
62+
server.listen(PORT, () => {
6263
console.log(`Server is running at http://localhost:${PORT}`);
6364
});

0 commit comments

Comments
 (0)