Created
April 20, 2020 13:33
-
-
Save Joe8Bit/4bc1c66a07b0c44f1cca24bbabcf8ad7 to your computer and use it in GitHub Desktop.
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
function getCookie(request, name) { | |
let result = null; | |
let cookieString = request.headers.get('Cookie'); | |
if (cookieString) { | |
let cookies = cookieString.split(';') | |
cookies.forEach(cookie => { | |
let cookieName = cookie.split('=')[0].trim() | |
if (cookieName === name) { | |
let cookieVal = cookie.split('=')[1] | |
result = cookieVal | |
} | |
}) | |
} | |
return result | |
} | |
async function handleRequest(request) { | |
let cookie = getCookie(request, '__BANKED-DEBUG') | |
if (cookie && cookie === 'TRUE') { | |
return Response('[banked-debug.js]') | |
} | |
return Response('[banked.js]') | |
} | |
addEventListener('fetch', event => { | |
event.respondWith(handleRequest(event.request)) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment