Last active
May 31, 2018 00:02
-
-
Save icodeforlove/9d22e44d0f227cb2740fd3db4d88af3f to your computer and use it in GitHub Desktop.
GDPR Block All European Countries (Cloudflare Worker)
This file contains 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 characters
const BLOCKED_COUNTRIES = [ | |
'AL', 'AD', 'AM', 'AT', 'BY', 'BE', 'BA', 'BG', 'CH', 'CY', 'CZ', 'DE', | |
'DK', 'EE', 'ES', 'FO', 'FI', 'FR', 'GB', 'GE', 'GI', 'GR', 'HU', 'HR', | |
'IE', 'IS', 'IT', 'LT', 'LU', 'LV', 'MC', 'MK', 'MT', 'NO', 'NL', 'PL', | |
'PT', 'RO', 'RU', 'SE', 'SI', 'SK', 'SM', 'TR', 'UA', 'VA' | |
]; | |
addEventListener('fetch', event => { | |
event.respondWith((async request => { | |
let country = request.headers.get('CF-IpCountry'), | |
ip = request.headers.get('CF-Connecting-IP'); | |
if (BLOCKED_COUNTRIES.indexOf(country) !== -1) { | |
return new Response(`Sorry, you are European and you can sue me from this IP: ${ip}`, { | |
status: 451, | |
headers: { | |
'Content-Type': 'text/html' | |
} | |
}); | |
} else { | |
return fetch(request); | |
} | |
})(event.request)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment