From 6b16b0b77e8930a3bf860fe96d0ff14f7984cc64 Mon Sep 17 00:00:00 2001 From: Matthew Bargar Date: Tue, 15 Mar 2016 16:51:25 -0400 Subject: [PATCH] Hapi can accept two methods for one route --- .../routes/api/search/count/register_count.js | 29 +++++++------------ 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/src/plugins/kibana/server/routes/api/search/count/register_count.js b/src/plugins/kibana/server/routes/api/search/count/register_count.js index 969906efb3484..8e542afe70cf0 100644 --- a/src/plugins/kibana/server/routes/api/search/count/register_count.js +++ b/src/plugins/kibana/server/routes/api/search/count/register_count.js @@ -2,14 +2,16 @@ import _ from 'lodash'; import handleESError from '../../../../lib/handle_es_error'; export default function registerCount(server) { - const path = '/api/kibana/{id}/_count'; - const handler = function (req, reply) { - const boundCallWithRequest = _.partial(server.plugins.elasticsearch.callWithRequest, req); + server.route({ + path: '/api/kibana/{id}/_count', + method: ['POST', 'GET'], + handler: function (req, reply) { + const boundCallWithRequest = _.partial(server.plugins.elasticsearch.callWithRequest, req); - boundCallWithRequest('count', { - allowNoIndices: false, - index: req.params.id - }) + boundCallWithRequest('count', { + allowNoIndices: false, + index: req.params.id + }) .then( function (res) { reply({count: res.count}); @@ -18,17 +20,6 @@ export default function registerCount(server) { reply(handleESError(error)); } ); - }; - - server.route({ - path, - method: 'POST', - handler - }); - - server.route({ - path, - method: 'GET', - handler + } }); }