Onedrive+OneManager+Heroku+CFWorkers Sweater New Weaving Method
//One day const SingleDay = '111.herokuapp.com' //Two-day const DoubleDay = '222.herokuapp.com' //All to CF agent, true/false const CFproxy = true //Since heroku cannot customize the domain name without binding the card, https is not convenient even after binding the card //In addition, the free package is 550 hours per month, which is not enough for some people //So we use this code in CF Workers to pull the same web page under different heroku accounts on separate orders and double days //Only change the upper part, not the lower part addEventListener('fetch', event => { let nd = new Date(); if (nd.getDate()%2) { host = SingleDay } else { host = DoubleDay } if (!CFproxy) { let url=new URL(event.request.url); if (url.protocol == 'http:') { url.protocol = 'https:' response = Response.redirect(url.href); event.respondWith( response ); } else { url.hostname=host; let request=new Request(url,event.request); event.respondWith( fetch(request) ) } } else { event.respondWith( fetchAndApply(event.request) ); } }) async function fetchAndApply(request) { let response = null; let url = new URL(request.url); if (url.protocol == 'http:') { url.protocol = 'https:' response = Response.redirect(url.href); return response; } url.host = host; let method = request.method; let body = request.body; let request_headers = request.headers; let new_request_headers = new Headers(request_headers); new_request_headers.set('Host', url.host); new_request_headers.set('Referer', request.url); let original_response = await fetch(url.href, { method: method, body: body, headers: new_request_headers }); response = new Response(original_response.body, { status: original_response.status, headers: original_response.headers }) return response; }
Copyright: Eric Qiu*
Link to this article: https://eblog.ink/archives/244/
The source and this statement shall be indicated when reprinting