1
+ import express from "express" ;
2
+ import path from "path" ;
3
+ import { fileURLToPath } from "url" ;
4
+ import fs from 'node:fs/promises' ;
5
+
6
+ import { load } from "@azure/app-configuration-provider" ;
7
+ const connectionString = "<your-connection-string>" ; ;
8
+ const appConfig = await load ( connectionString , {
9
+ featureFlagOptions : {
10
+ enabled : true ,
11
+ selectors : [ {
12
+ keyFilter : "*"
13
+ } ] ,
14
+ refresh : {
15
+ enabled : true
16
+ }
17
+ }
18
+ } ) ;
19
+
20
+ appConfig . onRefresh ( ( ) => {
21
+ console . log ( "Configuration has been refreshed." ) ;
22
+ } ) ;
23
+
24
+ import { ConfigurationObjectFeatureFlagProvider , ConfigurationMapFeatureFlagProvider , FeatureManager } from "@microsoft/feature-management" ;
25
+
26
+ /*
27
+ You can use either ConfigurationObjectFeatureFlagProvider or ConfigurationMapFeatureFlagProvider to provide feature flags.
28
+ We recommend using Azure App Configuration as the source of feature flags.
29
+ */
30
+ // const config = JSON.parse(await fs.readFile("config.json"));
31
+ // const featureProvider = new ConfigurationObjectFeatureFlagProvider(config);
32
+
33
+ const featureProvider = new ConfigurationMapFeatureFlagProvider ( appConfig ) ;
34
+ const featureManager = new FeatureManager ( featureProvider ) ;
35
+
36
+ const app = express ( ) ;
37
+ const PORT = 3000 ;
38
+
39
+ const __filename = fileURLToPath ( import . meta. url ) ;
40
+ const __dirname = path . dirname ( __filename ) ;
41
+
42
+ const pageDir = path . join ( __dirname , "pages" ) ;
43
+
44
+ app . get ( "/" , ( req , res ) => {
45
+ appConfig . refresh ( ) ;
46
+ res . sendFile ( path . join ( pageDir , "index.html" ) ) ;
47
+ } ) ;
48
+
49
+ app . get ( "/Beta" , async ( req , res ) => {
50
+ appConfig . refresh ( ) ;
51
+ const { userId, groups } = req . query ;
52
+
53
+ if ( await featureManager . isEnabled ( "Beta" , { userId : userId , groups : groups ? groups . split ( "," ) : [ ] } ) ) {
54
+ res . sendFile ( path . join ( pageDir , "beta.html" ) ) ;
55
+ } else {
56
+ res . status ( 404 ) . send ( "Page not found" ) ;
57
+ }
58
+ } ) ;
59
+
60
+ // Start the server
61
+ app . listen ( PORT , ( ) => {
62
+ console . log ( `Server is running at http://localhost:${ PORT } ` ) ;
63
+ } ) ;
0 commit comments