I need to send some push notifications to my app users when they do some stuff on our website.
I am using firebase to host my website, and am using ‘expo-server-sdk’ to make the request to push the notifications.
I am getting the following error:
Failed to load https://exp.host/--/api/v2/push/send: Response to preflight request doesn’t pass access control check: The ‘Access-Control-Allow-Origin’ header has a value ‘https://expo.io’ that is not equal to the supplied origin. Origin ‘https://bla.com’ is therefore not allowed access.
It sounds like you are trying to contact the Expo push service from a browser. It is not designed for that – your server is supposed to be responsible for sending notifications through Expo. (Heads up – with Firebase, you must be on a paid plan to contact non-Google servers from Firebase servers.)
Even with no-CORS, I believe you won’t be able to inspect the response from the Expo push server. This means you will not be able to look for DeviceNotRegistered errors and may continue sending notifications to inactive devices which can result in being blocked by Apple or Google.
You should send notifications from your server and always handle the response, especially for any production projects.
This is happening because of the CORS (Cross Origin Resource Sharing) error. This error occurs when you try to access a domain/resource from another domain. You cannot issue requests through the XMLHttpRequest to other domains or subdomains. For example, if you are doing something like writing HTML and Javascript in a code editor on your personal computer, and testing the output in your browser, you might probably get error messages about Cross Origin Requests .
JSONP ( JSON with Padding ) is a method commonly used to bypass the cross-domain policies in web browsers.
If this is for local development and you are using Chrome , you need to run Chrome with a couple of arguments to relax security like this:
The other easy way out, would be to create a proxy on your local server, which gets the remote request and then just forwards it back to your javascript.