cloudflare-trace-api icon indicating copy to clipboard operation
cloudflare-trace-api copied to clipboard

Javascript Example to JSON

Open fawazahmed0 opened this issue 4 years ago • 2 comments

async function getCloudflareJSON(){
let data = await fetch('https://1.0.0.1/cdn-cgi/trace').then(res=>res.text())
let arr = data.trim().split('\n').map(e=>e.split('='))
return Object.fromEntries(arr)
}

getCloudflareJSON().then(console.log)

Output:

{fl: "202f225", h: "1.0.0.1", ip: "47.37.137.777", ts: "1625581799.09", visit_scheme: "https", …}

fawazahmed0 avatar Jul 06 '21 14:07 fawazahmed0

How would you take this and filter out everything but "ip" and save that ip value as a variable to use later?

Wamy-Dev avatar Apr 23 '22 20:04 Wamy-Dev

async function somefunc(){
let cloudflareJSON = await getCloudflareJSON()
console.log(cloudflareJSON.ip)
}

fawazahmed0 avatar Apr 23 '22 23:04 fawazahmed0