Last active
April 1, 2020 19:13
-
-
Save nickturrietta/5c105f0a139eb97ca8b58d121547e1f4 to your computer and use it in GitHub Desktop.
Cloudflare Worker - Round Robin Redirect Test
This file contains hidden or 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
| 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