File size: 532 Bytes
a8aec61 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
export const constructEndpointUrl = (
value: string | null | undefined
): string => {
if (!value) return ''
if (value.startsWith('http://') || value.startsWith('https://')) {
return decodeURIComponent(value)
}
// Check if the endpoint is localhost or an IP address
if (
value.startsWith('localhost') ||
/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/.test(value)
) {
return `http://${decodeURIComponent(value)}`
}
// For all other cases, default to HTTPS
return `https://${decodeURIComponent(value)}`
}
|