@@ -7,6 +7,9 @@ static class ReverseProxy
77{
88 public static ( List < RouteConfig > routes , List < ClusterConfig > clusters ) GetConfiguration ( Settings settings )
99 {
10+ var routes = new List < RouteConfig > ( ) ;
11+ var clusters = new List < ClusterConfig > ( ) ;
12+
1013 var serviceControlInstance = new ClusterConfig
1114 {
1215 ClusterId = "serviceControlInstance" ,
@@ -15,17 +18,7 @@ public static (List<RouteConfig> routes, List<ClusterConfig> clusters) GetConfig
1518 { "instance" , new DestinationConfig { Address = settings . ServiceControlUri . ToString ( ) } }
1619 }
1720 } ;
18-
19- var monitoringInstance = new ClusterConfig
20- {
21- ClusterId = "monitoringInstance" ,
22- Destinations = new Dictionary < string , DestinationConfig >
23- {
24- { "instance" , new DestinationConfig { Address = settings . MonitoringUri . ToString ( ) } }
25- }
26- } ;
27-
28- var serviceControlRoute = new RouteConfig ( )
21+ var serviceControlRoute = new RouteConfig
2922 {
3023 RouteId = "serviceControlRoute" ,
3124 ClusterId = nameof ( serviceControlInstance ) ,
@@ -35,27 +28,30 @@ public static (List<RouteConfig> routes, List<ClusterConfig> clusters) GetConfig
3528 }
3629 } . WithTransformPathRemovePrefix ( "/api" ) ;
3730
38- var monitoringRoute = new RouteConfig ( )
39- {
40- RouteId = "monitoringRoute" ,
41- ClusterId = nameof ( monitoringInstance ) ,
42- Match = new RouteMatch
43- {
44- Path = "/monitoring-api/{**catch-all}"
45- }
46- } . WithTransformPathRemovePrefix ( "/monitoring-api" ) ;
47-
48- var routes = new List < RouteConfig >
49- {
50- serviceControlRoute ,
51- monitoringRoute
52- } ;
31+ clusters . Add ( serviceControlInstance ) ;
32+ routes . Add ( serviceControlRoute ) ;
5333
54- var clusters = new List < ClusterConfig >
34+ if ( settings . MonitoringUri != null )
5535 {
56- serviceControlInstance ,
57- monitoringInstance
58- } ;
36+ var monitoringInstance = new ClusterConfig
37+ {
38+ ClusterId = "monitoringInstance" ,
39+ Destinations = new Dictionary < string , DestinationConfig >
40+ {
41+ { "instance" , new DestinationConfig { Address = settings . MonitoringUri . ToString ( ) } }
42+ }
43+ } ;
44+
45+ var monitoringRoute = new RouteConfig
46+ {
47+ RouteId = "monitoringRoute" ,
48+ ClusterId = nameof ( monitoringInstance ) ,
49+ Match = new RouteMatch { Path = "/monitoring-api/{**catch-all}" }
50+ } . WithTransformPathRemovePrefix ( "/monitoring-api" ) ;
51+
52+ clusters . Add ( monitoringInstance ) ;
53+ routes . Add ( monitoringRoute ) ;
54+ }
5955
6056 return ( routes , clusters ) ;
6157 }
0 commit comments