Skip to content

Instantly share code, notes, and snippets.

@nickturrietta
Last active April 1, 2020 19:13
Show Gist options
  • Select an option

  • Save nickturrietta/5c105f0a139eb97ca8b58d121547e1f4 to your computer and use it in GitHub Desktop.

Select an option

Save nickturrietta/5c105f0a139eb97ca8b58d121547e1f4 to your computer and use it in GitHub Desktop.
Cloudflare Worker - Round Robin Redirect Test
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
const ministries = [
'mens',
'womens',
'youth',
'childrens',
'youngadult',
];
async function handleRequest(request) {
let int = randomInt(1, ministries.length);
let ministry = ministries[int-1];
let url = 'https://www.sdrock.com/ministries/' + ministry + '/';
return Response.redirect(url, 302)
}
function randomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment