feat: dynamic IP service domain resolution

Replaced static IP service URLs with dynamic hostname-based URLs in `getMyIP` function to ensure the IP service domain matches the current website's domain, excluding the 'www' prefix. This change enhances flexibility and adaptability, allowing the IP fetching functionality to work seamlessly across different deployments without needing manual URL updates for each domain.

- Removes hard-coded IP service domain.
- Utilizes `window.location.hostname` for dynamic domain resolution.
- Improves service compatibility across varying deployments.

This adjustment addresses potential issues with cross-origin requests and simplifies the deployment process for websites with multiple or changing domains.
This commit is contained in:
Kumi 2024-04-24 08:08:57 +02:00
parent b485ef06d0
commit 14b7d088a0
Signed by: kumi
GPG key ID: ECBCC9082395383F

View file

@ -1,5 +1,7 @@
function getMyIP() {
const domain = window.location.hostname.replace(/^www\./, '');
fetch('https://ipv4.' + domain)
.then(response => response.text())
.then(ipv4 => document.getElementById('ipv4').textContent = ipv4)
.catch(err => {
@ -7,7 +9,7 @@ function getMyIP() {
document.getElementById('ipv6').textContent = `Not available!`
fetch('https://ipv6.' + domain)
.then(response => response.text())
.then(ipv6 => document.getElementById('ipv6').textContent = ipv6)
.catch(err => {