Skip to content

Instantly share code, notes, and snippets.

@ramajd
Created February 28, 2023 06:52
Show Gist options
  • Save ramajd/9ef117be326a4989d1eabb3a7e5fa128 to your computer and use it in GitHub Desktop.
Save ramajd/9ef117be326a4989d1eabb3a7e5fa128 to your computer and use it in GitHub Desktop.
CF worker
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