I have created a kibana plugin using the following procedure:
goto kibana source directory
node scripts/generate_plugin test_plugin
build plugin with #yarn plugin-helpers build
I modified UI as it has some forms in frontend to accept user inputs. I created a routes in routes/index.ts has post call to handle this requests.
The post calls from kibana I want to redirect it to node server on port 3000.
Kibana plugin has @Hapi/h2o2 module installed which can be use for proxy handling, but I am not getting how to use it.
kibana source has interface âBasePathProxyServerOptionsâ for proxy handler in path
kibana/src/core/server/http//base_path_proxy_server.ts
I am new to nodejs, I am not sure how I will able to use this interface in my routes.
my post call in file /kibana/plugins/test_plugin/server/routes/index.ts:
I have tried to use http.request to send a post request to that external REST server, but it also not working as expected. when i added a CURL command with child_process.exec it's working fine. how can i replace that curl command with some http, or axios, or using Hapi itself?
Below is my code:
import { IRouter } from '../../../../src/core/server';
import { schema } from '@kbn/config-schema';
import * as command from 'child_process';
export function defineRoutes(router: IRouter) {
function runCmd(cmd)
{
var resp = command.execSync(cmd);
var result = resp.toString('UTF8');
return result;
}
router.post(
{
path: '/api/test_plugin/setIdentifier',
validate:
{
body: schema.object({
name: schema.string(),
}),
},
},
async(context, request, response) => {
var apiExec = `curl -s -d '{"name": "${request.body.name}" }' -H 'Content-Type: application/json' -H 'accept: application/json' http://node_server:3000/v1.0/setIdentifier`;
console.log(apiExec);
var result = JSON.parse(runCmd(apiExec));
return response.ok({
body:{
error: result.name,
statusCode: result.errorCode,
message: result.msg
}
});
}
)
}
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.