Created
December 22, 2020 20:05
-
-
Save minghao912/f44da8926183c8943ce99c7d4e763085 to your computer and use it in GitHub Desktop.
Cloudflare Worker to route URLs to different ports based on their protocol
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
addEventListener('fetch', event => { | |
const request = event.request; | |
let url = new URL(request.url); | |
console.log(request.url); | |
console.log(url); | |
if (url.protocol == "http:") | |
url.host = 'dragonfruit.tk:8080'; | |
else if (url.protocol == "https:") | |
url.host = 'dragonfruit.tk:8443'; | |
else | |
url.host = 'dragonfruit.tk:8080'; | |
console.log(url); | |
event.respondWith(fetch(url, request)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment