Kibana v6.2.4
In the dev mode, Kibana URL contains a random word which is changed after a restart, for example, poj
word here
http://localhost:5601/poj/app/myplugin#/?_g=()
How to get the word in a custom plugin server-side code?
In my Kibana plugin, I use server.inject()
async function logData(attributes) {
const resp = await server.inject({
method: 'PUT',
url: '/api/myplugin/alarm',
headers: {
'kbn-xsrf': 'reporting',
},
payload: {
attributes,
},
});
... do stuff
}
to query the plugin API route from the server code
server.route({
method: ['PUT'],
path: '/api/myplugin/alarm/{id?}',
config: {
validate: {
params: {
id: Joi.string(),
},
payload: {
attributes: Joi.object().required(),
},
},
},
handler: async function (req, reply) {
... do stuff
And it works when I run Kibana in the normal mode. But when I run it in the dev mode cd kibana && npm start
, I get a raw response with 404 Not Found
in the header:
{ raw:
{ res:
Response {
domain: [Object],
...
socket: [Object],
connection: [Object],
_header: 'HTTP/1.1 404 Not Found\r\nkbn-name: kibana\r\nkbn-version: 6.2.4\r\ncontent-type: application/json; charset=utf-8\r\ncache-control: no-cache\r\ncontent-length: 38\r\nDate: Mon, 17 Sep 2018 16:32:02 GMT\r\nConnection: keep-alive\r\n\r\n',
I understand this is because I don't have the random word in the server.inject()
url.
The related question on Stack Overflow: https://stackoverflow.com/q/52372513/2393924
Update
The example in the question works! The problem was that in my real code I used a wrong path in the route.