---------

**Commit 1:**
[url shortener] Use kibana.index config value, and fix silent error

* Original sha: 313bfc8ade
* Authored by Jim Unger <bigfunger@gmail.com> on 2016-04-21T21:22:58Z
This commit is contained in:
Elastic Jasper 2016-06-17 10:13:28 -04:00
parent 5099549ad4
commit ee39b00d3b
2 changed files with 18 additions and 8 deletions

View file

@ -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);
}
}
});

View file

@ -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;