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