File tree Expand file tree Collapse file tree 2 files changed +46
-2
lines changed Expand file tree Collapse file tree 2 files changed +46
-2
lines changed Original file line number Diff line number Diff line change 11{
22 "dependencies" : {
3- "@azure/app-configuration-provider" : " latest " ,
3+ "@azure/app-configuration-provider" : " 2.0.0-preview.2 " ,
44 "@azure/identity" : " ^4.1.0" ,
5- "dotenv" : " ^16.3.1"
5+ "dotenv" : " ^16.3.1" ,
6+ "express" : " ^4.21.2"
67 }
78}
Original file line number Diff line number Diff line change 1+ // Copyright (c) Microsoft Corporation.
2+ // Licensed under the MIT license.
3+
4+ import * as dotenv from "dotenv" ;
5+ dotenv . config ( )
6+
7+ import { load } from "@azure/app-configuration-provider" ;
8+ const connectionString = process . env . APPCONFIG_CONNECTION_STRING ;
9+ const appConfig = await load ( connectionString , {
10+ refreshOptions : {
11+ enabled : true
12+ }
13+ } ) ;
14+
15+ appConfig . onRefresh ( ( ) => {
16+ console . log ( "Config refreshed." ) ;
17+ } ) ;
18+
19+ import express from "express" ;
20+
21+ const app = express ( ) ;
22+ const PORT = 3000 ;
23+
24+ app . use ( express . json ( ) ) ;
25+
26+ app . get ( "/" , ( req , res ) => {
27+ appConfig . refresh ( ) ;
28+ res . send ( "Please go to /config to get the configuration." ) ;
29+ } ) ;
30+
31+ app . get ( "/config" , ( req , res ) => {
32+ appConfig . refresh ( ) ;
33+ res . json ( appConfig . constructConfigurationObject ( ) ) ;
34+ } ) ;
35+
36+ app . get ( "/config/:key" , ( req , res ) => {
37+ appConfig . refresh ( ) ;
38+ res . json ( appConfig . get ( req . params . key ) ?? "" ) ;
39+ } ) ;
40+
41+ app . listen ( PORT , ( ) => {
42+ console . log ( `Server is running on http://localhost:${ PORT } ` ) ;
43+ } ) ;
You can’t perform that action at this time.
0 commit comments