Skip to content

Commit

Permalink
Merge pull request #6353 from jbudz/issues/6061
Browse files Browse the repository at this point in the history
[url shortener] Add base path
  • Loading branch information
jbudz committed Feb 29, 2016
2 parents 4d3d119 + 59f8909 commit 6363abd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/server/http/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ module.exports = async function (kbnServer, server, config) {
path: '/goto/{urlId}',
handler: async function (request, reply) {
const url = await shortUrlLookup.getUrl(request.params.urlId);
reply().redirect(url);
reply().redirect(config.get('server.basePath') + url);
}
});

Expand Down
7 changes: 5 additions & 2 deletions src/ui/public/share/lib/url_shortener.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import chrome from 'ui/chrome';

export default function createUrlShortener(Notifier, $http, $location) {
const notify = new Notifier({
location: 'Url Shortener'
});
const baseUrl = `${$location.protocol()}://${$location.host()}:${$location.port()}`;
const basePath = chrome.getBasePath();
const baseUrl = `${$location.protocol()}://${$location.host()}:${$location.port()}${basePath}`;

async function shortenUrl(url) {
const relativeUrl = url.replace(baseUrl, '');
const formData = { url: relativeUrl };

try {
const result = await $http.post('/shorten', formData);
const result = await $http.post(`${basePath}/shorten`, formData);

return `${baseUrl}/goto/${result.data}`;
} catch (err) {
Expand Down

0 comments on commit 6363abd

Please sign in to comment.