Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling fetch function for push notifications in service worker causes CORS error #878

Open
3 tasks done
MrMelon1232 opened this issue Jan 11, 2024 · 1 comment
Open
3 tasks done

Comments

@MrMelon1232
Copy link

MrMelon1232 commented Jan 11, 2024

Hi, I have an app that calls a api fetch call for push notifications in the service worker and it returns the follow error:
Access to fetch at 'ressource from server' from origin 'domain' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Operating System: Windows
Node Version: latest
web-push Version: latest

Please select any browsers that you are experiencing problems with:

  • Chrome
  • Firefox
  • Edge

Problem

As mentioned before, the issue is that we are getting a CORS error, but other fetch functions called by the service worker works fine. I was wondering if the vapid keys might have anything to do with it ? On top of this, I only get this issue on my deployed app using vercel and not locally. I've tried to add the following lines to my server file:
app.use((req, res, next) => {
res.setHeader("Access-Control-Allow-Origin", "*");
next();
});
but unfortunately I still get the error. Since I am not getting an error with my other fetch calls, I was wondering maybe web-push has specifics to setup or any of the sort. Any help would be appreciated!

Features Used

  • [ x] VAPID Support
  • [x ] GCM API Key
  • [ x] Sending with Payload
@ilyahorski
Copy link

Hi! Same for me. I'm encountering a CORS error on a Vercel deployment client after I added web-push logic to my Heroku socket server. I also tried to allow all domains on the client and server in the headers, but this did not work. Were you able to find a solution to the problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants