redirect.js 461 B

12345678910111213141516171819
  1. export async function onRequest(context) {
  2. const { request, env } = context;
  3. let url = request.url;
  4. let iSlash = url.indexOf('?',11);
  5. let nUrl = url.substring(iSlash+1);
  6. return await goUrl(request, nUrl);
  7. }
  8. async function goUrl(request, url) {
  9. const Url = new URL(url);
  10. const newReq = new Request(Url, {
  11. method: request.method,
  12. headers: request.headers,
  13. body: request.body,
  14. redirect: 'follow'
  15. })
  16. return await fetch(newReq);
  17. }