redirect2.js 523 B

12345678910111213141516171819202122
  1. export default {
  2. async fetch(req, _env) {
  3. let url = req.url;
  4. const Url = new URL(url);
  5. let iSlash = url.indexOf('/',11);
  6. let nUrl = url.substring(iSlash+1);
  7. return await goUrl(req, nUrl);
  8. }
  9. }
  10. async function goUrl(request, url) {
  11. const Url = new URL(url);
  12. let headers = new Headers(request.headers);
  13. headers.set("X-forwarded-for","104.28.5.161");
  14. const newReq = new Request(Url, {
  15. method: request.method,
  16. headers: headers,
  17. body: request.body
  18. })
  19. return await fetch(newReq);
  20. }