|
|
|
@ -1,17 +1,17 @@
|
|
|
|
|
import * as url from 'url-parse'; |
|
|
|
|
import * as url from 'url'; |
|
|
|
|
|
|
|
|
|
export function normalizeUrl(grafanaUrl: string) { |
|
|
|
|
if(!grafanaUrl) { |
|
|
|
|
return grafanaUrl; |
|
|
|
|
} |
|
|
|
|
let urlObj = new url(grafanaUrl); |
|
|
|
|
let urlObj = url.parse(grafanaUrl); |
|
|
|
|
if(urlObj.protocol !== 'http:' && urlObj.protocol !== 'https:') { |
|
|
|
|
grafanaUrl = `http://${grafanaUrl}`; |
|
|
|
|
urlObj = new url(grafanaUrl); |
|
|
|
|
urlObj = url.parse(grafanaUrl); |
|
|
|
|
console.log('No protocol provided in GRAFANA_URL -> inserting "http://"'); |
|
|
|
|
} |
|
|
|
|
if(urlObj.slashes === false) { |
|
|
|
|
urlObj = new url(`${urlObj.protocol}//${urlObj.pathname}`); |
|
|
|
|
urlObj = url.parse(`${urlObj.protocol}//${urlObj.pathname}`); |
|
|
|
|
console.log('No slashes were provided after the protocol -> inserting slashes'); |
|
|
|
|
}
|
|
|
|
|
if(urlObj.pathname.slice(-1) === '/') { |
|
|
|
@ -19,7 +19,7 @@ export function normalizeUrl(grafanaUrl: string) {
|
|
|
|
|
console.log('Removing the slash at the end of GRAFANA_URL'); |
|
|
|
|
} |
|
|
|
|
let finalUrl = `${urlObj.protocol}//${urlObj.hostname}`; |
|
|
|
|
if(urlObj.port !== '') { |
|
|
|
|
if(urlObj.port !== null) { |
|
|
|
|
finalUrl = finalUrl + ':' + urlObj.port; |
|
|
|
|
} |
|
|
|
|
if(urlObj.pathname !== '') { |
|
|
|
|