redirect.js 430 B

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