diff --git a/index.js b/index.js index 330f6675cc0bf..5afdfb821a160 100644 --- a/index.js +++ b/index.js @@ -85,36 +85,30 @@ module.exports = function (kibana) { } const proxyConfigCollection = new ProxyConfigCollection(options.proxyConfig); + const proxyRouteConfig = { + validate: { + query: Joi.object().keys({ + uri: Joi.string().uri({ + allowRelative: false, + shema: ['http:', 'https:'], + }), + }).unknown(true), + }, - // http://hapijs.com/api/8.8.1#route-configuration - server.route({ - path: '/api/sense/proxy', - method: ['*', 'GET'], - config: { - validate: { - query: Joi.object().keys({ - uri: Joi.string().uri({ - allowRelative: false, - shema: ['http:', 'https:'], - }), - }).unknown(true), - }, - - pre: [ - function filterUri(req, reply) { - const { uri } = req.query; - - if (!filters.some(re => re.test(uri))) { - const err = Boom.forbidden(); - err.output.payload = "Error connecting to '" + uri + "':\n\nUnable to send requests to that url."; - err.output.headers['content-type'] = 'text/plain'; - reply(err); - } else { - reply(); - } + pre: [ + function filterUri(req, reply) { + const { uri } = req.query; + + if (!filters.some(re => re.test(uri))) { + const err = Boom.forbidden(); + err.output.payload = "Error connecting to '" + uri + "':\n\nUnable to send requests to that url."; + err.output.headers['content-type'] = 'text/plain'; + reply(err); + } else { + reply(); } - ] - }, + } + ], handler(req, reply) { const { uri } = req.query; @@ -134,8 +128,29 @@ module.exports = function (kibana) { ...proxyConfigCollection.configForUri(uri) }) } + }; + + server.route({ + path: '/api/sense/proxy', + method: '*', + config: { + ...proxyRouteConfig, + + payload: { + output: 'stream', + parse: false + }, + } }); + server.route({ + path: '/api/sense/proxy', + method: 'GET', + config: { + ...proxyRouteConfig + } + }) + server.route({ path: '/api/sense/api_server', method: ['GET', 'POST'],