Skip to content

Commit

Permalink
Merge pull request #9 from adaptive/patch-1
Browse files Browse the repository at this point in the history
PoP location detection
  • Loading branch information
eidam authored Nov 17, 2020
2 parents 8eadbb3 + 01c058e commit 126a48b
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/functions/cronTrigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@ export async function processCronTrigger(event) {
}

// save last check timestamp including PoP location
const res = await fetch("https://www.cloudflare.com/cdn-cgi/trace")
const resText = await res.text()
const loc = /loc=([\w]{2})/.exec(resText)[1]
await setKV('lastUpdate', Date.now(), {loc})
const res = await fetch('https://cloudflare-dns.com/dns-query', {
method: 'OPTIONS',
})
const loc = res.headers.get('cf-ray').split('-')[1]
await setKV('lastUpdate', Date.now(), { loc })

// gc monitor statuses
event.waitUntil(gcMonitors(config))
Expand Down

0 comments on commit 126a48b

Please sign in to comment.