Im trying to send push notifications directly from a React frontend (non react-native). Curl and the expo push notification tool works fine. Only when I send if from my React frontend from ‘localhost:3000’, I am getting this error:
Access to fetch at 'https://exp.host/--/api/v2/push/send' from origin 'http://localhost:3000'
has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present
Failed to fetch
React Code
class Form extends React.Component {
handleSearch(event) {
event.preventDefault();
const message = {
to: "ExponentPushToken[T0ZuCoB1o4ypzCbOtu2NK9]",
sound: 'default',
title: 'Original Title',
body: 'And here is the body!',
data: { data: 'goes here' },
};
fetch('https://exp.host/--/api/v2/push/send', {
method: 'POST',
headers: {
Accept: 'application/json',
'Accept-encoding': 'gzip, deflate',
'Content-Type': 'application/json',
'Access-Control-Allow-Origin':'*'
},
body: JSON.stringify(message),
});
render() {
return (
<div>
<input placeholder="Send a notification" onChange={this.handleTermChange} />
</div>
<div>
<a onClick={this.handleSearch}>Send Push Notification</a>
</div>
</div>
)}