Failed to fetch from React frontend (non react-native)

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 '' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present 
Failed to fetch

My React Code

  handleSearch(event) {
    const message = {
        to: "ExponentPushToken[T01234ZuCoOtu2NK9]",
        sound: 'default',
        title: 'Original Title',
        body: 'And here is the body!',
        data: { data: 'goes here' },
        _displayInForeground: true,
      fetch('', {
        method: 'POST',
        headers: {
          Accept: 'application/json',
          'Accept-encoding': 'gzip, deflate',
          'Content-Type': 'application/json',
        body: JSON.stringify(message),

  render() {
    return (
          <input placeholder="Send a notification" onChange={this.handleTermChange} />
          <a onClick={this.handleSearch}>Send Push Notification</a>

1 Like