File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5,15 +5,24 @@ import { env, eureka } from '@greeting/shared';
55const app = express ( ) ;
66const eurekaClient = await eureka . getClient ( env . port ) ;
77
8- const lookupService = ( ) => {
9- return eurekaClient . getInstancesByAppId ( 'GREETER-MESSAGES' ) [ 0 ] ?. hostName ;
8+ const serviceHost = ( ) => {
9+ const instances =
10+ eurekaClient
11+ . getInstancesByAppId ( 'GREETER-MESSAGES' )
12+ ?. filter ( ( instance ) => instance . status === 'UP' ) || [ ] ;
13+
14+ if ( instances . length === 0 ) {
15+ throw new Error ( 'No instances of GREETER-MESSAGES available' ) ;
16+ }
17+
18+ return instances [ 0 ] . hostName ;
1019} ;
1120
1221app . get ( '/hello' , async ( req , res ) => {
1322 const salutation = req . query . salutation || 'Hello' ;
1423 const name = req . query . name || 'Bob' ;
1524
16- const url = `https://${ lookupService ( ) } /greeting?salutation=${ salutation } &name=${ name } ` ;
25+ const url = `https://${ serviceHost ( ) } /greeting?salutation=${ salutation } &name=${ name } ` ;
1726
1827 const response = await axios . get ( `${ url } ` , {
1928 headers : {
Original file line number Diff line number Diff line change @@ -25,6 +25,10 @@ const getClient = async (port) => {
2525 $ : port ,
2626 '@enabled' : true ,
2727 } ,
28+ securePort : {
29+ $ : port ,
30+ '@enabled' : true ,
31+ } ,
2832 vipAddress : 'UNKNOWN' ,
2933 dataCenterInfo : {
3034 '@class' : 'com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo' ,
You can’t perform that action at this time.
0 commit comments