Created
January 13, 2021 09:11
-
-
Save Klumper/d3e7f704f332dc29269a3601c4756881 to your computer and use it in GitHub Desktop.
Trace current user's location with javascript fetch, using cloudflare.com/cdn-cgi/trace.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const cloudflareTrace = async () => { | |
try { | |
const response = await fetch('https://www.cloudflare.com/cdn-cgi/trace') | |
const rawData = await response.text(); | |
const jsonData = Object.fromEntries( | |
rawData.trim() | |
.split('\n') | |
.map(line => line.split('=')) | |
); | |
return jsonData; | |
} catch (error) { | |
console.error(`cloudflareTrace: ${error}`); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment