Skip to content

Instantly share code, notes, and snippets.

@shagamemnon
Created March 17, 2020 04:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shagamemnon/36e7529e2b593bc7257e42a342335d86 to your computer and use it in GitHub Desktop.
Save shagamemnon/36e7529e2b593bc7257e42a342335d86 to your computer and use it in GitHub Desktop.
addEventListener('fetch', event => {
event.respondWith(handleRequest(event))
})
async function timeout (ms) {
return new Promise(accept => {
setTimeout(() => {
accept('timeout')
}, ms)
})
}
async function handleRequest (request) {
if (request.cf.botManagement.score && request.cf.botManagement.score < 70) {
await timeout(5000)
}
return fetch(request)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment