Skip to content
This repository has been archived by the owner on Mar 31, 2024. It is now read-only.

Commit

Permalink
Merge pull request elastic#123 from spalger/fix/proxyReqsWithBody
Browse files Browse the repository at this point in the history
Fix proxy reqs with body
(cherry picked from commit babc531bc68f14cc7eba70dca3a1eabcb10b7787)
  • Loading branch information
spalger committed Mar 11, 2016
1 parent 65a0579 commit 99863df
Showing 1 changed file with 43 additions and 28 deletions.
71 changes: 43 additions & 28 deletions index.js
Original file line number Diff line number Diff line change
@@ -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'],

0 comments on commit 99863df

Please sign in to comment.