Skip to content

Commit 0d77687

Browse files
committed
Configure secure port
Signed-off-by: kvmw <mshamsi@broadcom.com>
1 parent ec44991 commit 0d77687

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

packages/greeter/server.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,24 @@ import { env, eureka } from '@greeting/shared';
55
const app = express();
66
const 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

1221
app.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: {

packages/shared/src/eureka.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff 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',

0 commit comments

Comments
 (0)