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.
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
The Access-Control-Allow-Origin header
Have you even Googled it...
https://developers.cloudflare.com/workers/examples/cors-header-proxy
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.