I'm currently developing a plugin for Kibana (7.0, es 7.0, win10), but I'm having an unexpected issue. The first two routes I created worked fine (under server/routes/routing.js) but for some reason the third one won't be created, and no log would show up in console even though I call console.log().
Here is my code:
async function getStatuses(server){
let promise = fetch("http://es_instance:port/index/_search",{
method: "GET",
mode: "cors",
headers: {"Content-Type": "application/json"},
body: {
"query": { "match_all": {} },
"aggs": {
"max_status": {
"max": {
"field": "global_status",
"missing": 0
}
}
}
}
}).then(res=>res.json()).then(body=>{
console.log(body);
let a = body.hits.hits;
return { global_status: body.aggregations.max_status.value,
last_message: a[a.length-1] };
});
let res = await promise;
console.log(res);
server.route({
path: '/api/my_plugin_name/my_route',
method: 'GET',
handler() {
return { statuses: JSON.stringify(res) };
}
});
}
My function is called there:
export default function (server) {
[...]//registering routes in API
getStatuses(server);
}
When I'm hitting directly /api/my_plugin_name/my_route
, I get a 404. Is it possible that registering routes can somehow return (stop function execution) before getStatuses()
is even called? Or am I missing something?