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