我正在尝试将以下代码调整为如果列表中的国家/地区则允许,如果没有则阻止,当前代码如果列表中的国家/地区则阻止,如果不是则允许
addEventListener('fetch', event => {
event.respondWith(blockCountries(event.request))
})
//Add countries to this Set to block them
const countries = new Set([
"US", // United States
"SG", // Singapore
"BR" // Brazil
])
async function blockCountries(request) {
// Get country value from request headers
let country = request.headers.get('cf-ipcountry')
// Find out if country is on the block list
let countryBlocked = countries.has(country)
// If it's on the blocked list, give back a 403
if (countryBlocked){
return new Response("This page not available in your country",
{ status: 403, statusText: "Forbidden" })
}
// Catch-all return of the original response
return await fetch(request)
}
调整这个的任何提示