-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathindex.js
More file actions
20 lines (16 loc) · 566 Bytes
/
index.js
File metadata and controls
20 lines (16 loc) · 566 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
const IPIFY_ENDPOINT_IPV4 = 'https://api.ipify.org';
const IPIFY_ENDPOINT_IPV6 = 'https://api6.ipify.org';
export default async function ipify({useIPv6 = true, endpoint} = {}) {
endpoint ??= useIPv6 ? IPIFY_ENDPOINT_IPV6 : IPIFY_ENDPOINT_IPV4;
if (Array.isArray(endpoint)) {
if (endpoint.length === 0) {
throw new TypeError('Endpoint array cannot be empty');
}
return Promise.any(endpoint.map(async url => {
const response = await fetch(url);
return response.text();
}));
}
const response = await fetch(endpoint);
return response.text();
}