From ee39b00d3b339aa98b096ea2fdb15b11f326c300 Mon Sep 17 00:00:00 2001 From: Elastic Jasper Date: Fri, 17 Jun 2016 10:13:28 -0400 Subject: [PATCH] Backport PR #7009 --------- **Commit 1:** [url shortener] Use kibana.index config value, and fix silent error * Original sha: 313bfc8adefdc25ca7f2e2f186f764fd00291212 * Authored by Jim Unger on 2016-04-21T21:22:58Z --- src/server/http/index.js | 16 ++++++++++++---- src/server/http/short_url_lookup.js | 10 ++++++---- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/server/http/index.js b/src/server/http/index.js index 58076145c97ec..120f877c7b559 100644 --- a/src/server/http/index.js +++ b/src/server/http/index.js @@ -163,8 +163,12 @@ module.exports = function (kbnServer, server, config) { method: 'GET', path: '/goto/{urlId}', handler: async function (request, reply) { - const url = await shortUrlLookup.getUrl(request.params.urlId); - reply().redirect(config.get('server.basePath') + url); + try { + const url = await shortUrlLookup.getUrl(request.params.urlId); + reply().redirect(config.get('server.basePath') + url); + } catch (err) { + reply(err); + } } }); @@ -172,8 +176,12 @@ module.exports = function (kbnServer, server, config) { method: 'POST', path: '/shorten', handler: async function (request, reply) { - const urlId = await shortUrlLookup.generateUrlId(request.payload.url); - reply(urlId); + try { + const urlId = await shortUrlLookup.generateUrlId(request.payload.url); + reply(urlId); + } catch (err) { + reply(err); + } } }); diff --git a/src/server/http/short_url_lookup.js b/src/server/http/short_url_lookup.js index 4ced5e5d812a9..033a040d4f8ac 100644 --- a/src/server/http/short_url_lookup.js +++ b/src/server/http/short_url_lookup.js @@ -3,10 +3,11 @@ const crypto = require('crypto'); export default function (server) { async function updateMetadata(urlId, urlDoc) { const client = server.plugins.elasticsearch.client; + const kibanaIndex = server.config().get('kibana.index'); try { await client.update({ - index: '.kibana', + index: kibanaIndex, type: 'url', id: urlId, body: { @@ -25,9 +26,10 @@ export default function (server) { async function getUrlDoc(urlId) { const urlDoc = await new Promise((resolve, reject) => { const client = server.plugins.elasticsearch.client; + const kibanaIndex = server.config().get('kibana.index'); client.get({ - index: '.kibana', + index: kibanaIndex, type: 'url', id: urlId }) @@ -45,9 +47,10 @@ export default function (server) { async function createUrlDoc(url, urlId) { const newUrlId = await new Promise((resolve, reject) => { const client = server.plugins.elasticsearch.client; + const kibanaIndex = server.config().get('kibana.index'); client.index({ - index: '.kibana', + index: kibanaIndex, type: 'url', id: urlId, body: { @@ -79,7 +82,6 @@ export default function (server) { return { async generateUrlId(url) { const urlId = createUrlId(url); - const urlDoc = await getUrlDoc(urlId); if (urlDoc) return urlId;