I am creating a visualization plugin for extracting all filters that is applied to the current dashboard and submit it to an external rest API. It is working effortlessly in my local development environment (ES & Kibana 7.9.2), but as soon as I install the plugin on my server machine, I get a 404 - Not Found error when I try to make a call to my route.
As far as I see the call is not even arriving at the route. The error is for a post at the path for the defined route.
Here is a screenshot from the DevTools:
Here is the call that I make in my plugin to access my defined route, which is located under <plugin-root>/public/plugin_controller.tsx
:
$.ajax({
url: '/api/dashboardfilterexporter/submit',
type: 'POST',
cache: false,
contentType: 'application/json',
data: requestData,
success: function (result) {
console.info('Success');
},
error: function (error) {
console.error('ERROR');
console.error(error);
}
})
And this is the defined route that should get called, located under <plugin-root>/server/routes.ts
:
router.post(
{
path: '/api/dashboardfilterexporter/submit',
validate: {
body: schema.object({
url: schema.string(),
query: schema.string()
})
},
},
async (context: RequestHandlerContext, request: KibanaRequest, response) => {
const query = JSON.parse(request.body.query);
const url = new URL(request.body.url);
var options = {
protocol: url.protocol,
host: url.hostname,
port: url.port,
path: url.pathname,
method: 'POST',
headers: {
'Content-Type': 'text/plain'
}
};
return new Promise((resolve, reject) => {
const req = http.request(options, (res) => {
res.setEncoding('utf8');
res.on('data', (d) => {
logger.info(`Successful`);
resolve(response.ok());
});
});
req.on('error', (e) => {
reject(response.notFound());
})
req.write(query);
req.end();
}).catch(err => {
logger.error(`Failed`);
logger.error(err);
if (err.status == 404) {
return response.notFound(err);
} else {
return response.badRequest(err);
}
})
}
)
It works locally, so what I expect is that there is something blocking the call somehow, but I though as long as it is within Kibana, it should not be a problem?