Created
February 28, 2023 06:52
-
-
Save ramajd/9ef117be326a4989d1eabb3a7e5fa128 to your computer and use it in GitHub Desktop.
CF worker
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
export default { | |
async fetch(req) { | |
try { | |
const url = new URL(req.url); | |
const splitted = url.pathname.replace(/^\/*/, '').split('/'); | |
const address = splitted[0]; | |
url.pathname = splitted.slice(1).join('/'); | |
url.hostname = address; | |
url.protocol = 'https'; | |
return fetch(new Request(url, req)); | |
} catch (e) { | |
return new Response(e); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment