From 01c058ed1bf23e688af8350cf005725aa2881599 Mon Sep 17 00:00:00 2001 From: Hugo Romano Date: Tue, 17 Nov 2020 15:35:49 +0000 Subject: [PATCH] PoP location detection --- src/functions/cronTrigger.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/functions/cronTrigger.js b/src/functions/cronTrigger.js index 6deee6c..da7082c 100644 --- a/src/functions/cronTrigger.js +++ b/src/functions/cronTrigger.js @@ -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))