1
0
forked from noxious/client

#190 : Cookie domain improvement

This commit is contained in:
2024-10-30 07:17:07 +01:00
parent 7c259f455c
commit 08f55c9680
3 changed files with 21 additions and 6 deletions

View File

@ -5,3 +5,21 @@ export function uuidv4() {
export function unduplicateArray(array: any[]) {
return [...new Set(array.flat())]
}
export function getDomain() {
// Check if not localhost
if (window.location.hostname !== 'localhost') {
return window.location.hostname
}
// Check if not IP address
if (window.location.hostname.match(/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/)) {
return window.location.hostname
}
if (window.location.hostname.split('.').length < 3) {
return window.location.hostname
}
return window.location.hostname.split('.').slice(-2).join('.')
}