Hi all,
We were trying to read the elasticsearch cluster hosts in out plugin's server-side, but we were unable to find anything in the context
parameter in callback function.
as shown in below code:
export function defineRoutes(router: IRouter, client: IScopedClusterClient, config: HttpServerInfo) {
router.get(
{
path: '/endpoint',
validate: false,
},
async (context, request, response) => {
const requestOptions = {
method: 'GET',
headers: { 'Content-Type': 'application/json', 'Cluster': process.env["cluster"], 'Authorization': request.headers.authorization },
agent: httpsAgent
};
const info = await context.core.elasticsearch.client.asCurrentUser.nodes.info()
return fetch(serverURL + '/endpoint/', requestOptions)
.then(response => {
logger.info('Enpoint: Endpoint success');
logger.info(info)
if (response.status == 200) {
return response.json()
} else {
throw new Error(response)
}
}).then(res => {
return response.ok({
body: {
Response: res
},
});
})
.catch(async (err) => {
logger.info('EndPoint : ' + err);
let message_ = await err.text().then(mm => {
return mm;
});
var resp_ = response.custom({
body: {
message: message_
},
statusCode: err.status
});
return resp_;
});
}
);
}
Neither I was able to find in const cluster = await config.hostname
with the HttpServerInfo
.
Please suggest any alternatives to retrieve the desired information.
Thanks and regards
Chaitanya