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:
parent
b485ef06d0
commit
14b7d088a0
1 changed files with 4 additions and 2 deletions
|
@ -1,5 +1,7 @@
|
|||
function getMyIP() {
|
||||
fetch('https://ipv4.myip.coffee')
|
||||
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.myip.coffee')
|
||||
fetch('https://ipv6.' + domain)
|
||||
.then(response => response.text())
|
||||
.then(ipv6 => document.getElementById('ipv6').textContent = ipv6)
|
||||
.catch(err => {
|
||||
|
|
Loading…
Reference in a new issue