Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


How to allow CORS in cloudflare workers?
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

How to allow CORS in cloudflare workers?

I'm using cloudflare workers to create a reverse proxy but I can't use it to embed on main domain cause it gives CORS error:

Access to image at 'https://example.workers.dev/96384873_p0.png' from origin 'https://example.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

here's the code in workers

addEventListener("fetch", event => {
  let url = new URL(event.request.url);
  url.hostname = "i.pximg.net";
  let request = new Request(url, event.request);
  event.respondWith(
    fetch(request, {
      headers: {
        'Referer': 'https://www.pixiv.net/',
        'User-Agent': 'Cloudflare Workers'
      }
    })
  );
});

How can I fix the CORS error?

Comments

  • jackbjackb Member, Host Rep
    edited February 2022

    The Access-Control-Allow-Origin header

  • FAT32FAT32 Administrator, Deal Compiler Extraordinaire
  • jmgcaguiclajmgcaguicla Member
    edited February 2022

    Christ, the way this guy treats LET is even worse than StackOverflow.

    At least I get fake internet points when I answer stupid questions on SO.

    Thanked by 2Erisa JeDaYoshi
  • @jmgcaguicla said:
    Christ, the way this guy treats LET is even worse than StackOverflow.

    At least I get fake internet points when I answer stupid questions on SO.

    To be fair, this is a forum mainly for hosting offers, that's what people are most interested in. The eventual drama and a slight interesting topic also works at times.

    But regardless, I agree that it'd be better if we didn't treat other users as shit for asking stuff, tbh. If it's a Google-level question the thread is just gonna get lost anyway in a day.

Sign In or Register to comment.