forked from flexmonster/pivot-kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
44 lines (44 loc) · 1.35 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
export default function (kibana) {
return new kibana.Plugin({
require: ['elasticsearch'],
name: 'flexmonster_pivot',
uiExports: {
app: {
title: 'Flexmonster Pivot',
description: 'Flexmonster Pivot Table',
main: 'plugins/flexmonster_pivot/app',
icon: 'plugins/flexmonster_pivot/logo.png'
},
},
config(Joi) {
return Joi.object({
enabled: Joi.boolean().default(true),
}).default();
},
init(server, options) { // eslint-disable-line no-unused-vars
server.route({
path: '/api/flexmonster_pivot/es',
method: 'GET',
handler: (req) => {
return new Promise((resolve, reject) => {
server.newPlatform.setup.core.elasticsearch.dataClient$.subscribe(client => {
const url = new URL(client.config.hosts[0]);
const esConfig = {
"host": {
"protocol": url.protocol.replace(/:/g, ''),
"host": url.hostname,
"port": url.port,
"path": url.pathname,
"headers": {
"authorization": req.headers.authorization
}
}
}
resolve(esConfig);
});
});
}
});
}
});
}