kibana-riya
Version:
Kibana is an open source (Apache Licensed), browser based analytics and search dashboard for Elasticsearch. Kibana is a snap to setup and start using. Kibana strives to be easy to get started with, while also being flexible and powerful, just like Elastic
34 lines (27 loc) • 853 B
JavaScript
import chrome from 'ui/chrome';
import url from 'url';
export default function createUrlShortener(Notifier, $http, $location) {
const notify = new Notifier({
location: 'Url Shortener'
});
function shortenUrl(absoluteUrl) {
const basePath = chrome.getBasePath();
const parsedUrl = url.parse(absoluteUrl);
const path = parsedUrl.path.replace(basePath, '');
const hash = parsedUrl.hash ? parsedUrl.hash : '';
const relativeUrl = path + hash;
const formData = { url: relativeUrl };
return $http.post(`${basePath}/shorten`, formData).then((result) => {
return url.format({
protocol: parsedUrl.protocol,
host: parsedUrl.host,
pathname: `${basePath}/goto/${result.data}`
});
}).catch((response) => {
notify.error(response);
});
}
return {
shortenUrl
};
};