Bulk origin override
Resolve requests to your domain to a set of proxy third-party origin URLs.
export default {async fetch(request) {/*** An object with different URLs to fetch* @param {Object} ORIGINS*/const ORIGINS = {"starwarsapi.yourdomain.com": "swapi.dev","google.yourdomain.com": "www.google.com",};const url = new URL(request.url);// Check if incoming hostname is a key in the ORIGINS objectif (url.hostname in ORIGINS) {const target = ORIGINS[url.hostname];url.hostname = target;// If it is, proxy request to that third party originreturn fetch(url.toString(), request);}// Otherwise, process request as normalreturn fetch(request);},};
const handler: ExportedHandler = {async fetch(request: Request) {/*** An object with different URLs to fetch* @param {Object} ORIGINS*/const ORIGINS = {"starwarsapi.yourdomain.com": "swapi.dev","google.yourdomain.com": "www.google.com",};const url = new URL(request.url);// Check if incoming hostname is a key in the ORIGINS objectif (url.hostname in ORIGINS) {const target = ORIGINS[url.hostname];url.hostname = target;// If it is, proxy request to that third party originreturn fetch(url.toString(), request);}// Otherwise, process request as normalreturn fetch(request);},};export default handler;