Last active
December 1, 2023 15:52
-
-
Save dogweather/051f0743de9d941bb1a0b8a8a7f8f6ff to your computer and use it in GitHub Desktop.
Revisions
-
dogweather revised this gist
Dec 1, 2023 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,11 @@ async function handleRequest(request) { // Is the visitor in the VIP list? let data = request.cf let visitor_asn = data.asn // Query the KV database let network_name = await VIP_API_ASN.get(visitor_asn) // Create the HTTP header value let is_vip = (network_name !== null) let msg = 'vip: ' + (is_vip ? 'yes' : 'no ') + '; ' + data.asn.toString().padStart(7) + ' - ' + data.asOrganization console.log(msg); -
dogweather created this gist
Dec 1, 2023 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ async function handleRequest(request) { // Is the visitor in the VIP list? let data = request.cf let visitor_asn = data.asn let network_name = await VIP_API_ASN.get(visitor_asn) let is_vip = (network_name !== null) let msg = 'vip: ' + (is_vip ? 'yes' : 'no ') + '; ' + data.asn.toString().padStart(7) + ' - ' + data.asOrganization console.log(msg); // Clone the request so that it's no longer immutable const newRequest = new Request(request); // Add a custom header with the VIP message newRequest.headers.append("x-vip", msg) // Send the request on its way let response = await fetch(newRequest); // Return the response to the user return response } addEventListener('fetch', event => { event.respondWith(handleRequest(event.request)); });