title: How to create a proxy in React/Webpack to call an external API
body: <p>I want to issue a GET request to an external API that I do not control. Because of the security on the API, my react app cannot directly make an ajax request to the endpoint. Therefore I'm trying to create a simple proxy as demonstrated <a href="https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#configuring-the-proxy-manually" rel="noreferrer">here</a></p>
  
  <p>My <code>package.json file</code> looks like this:</p>
  
  <pre><code>{
    "name": "my-stack",
    "version": "0.1.0",
    "private": true,
    "dependencies": {
      "react": "^15.6.1",
      "react-dom": "^15.6.1",
      "react-router-dom": "^4.2.2",
      "react-scripts": "1.0.13"
    },
    "scripts": {
      "start": "react-scripts start",
      "build": "react-scripts build",
      "test": "react-scripts test --env=jsdom",
      "eject": "react-scripts eject"
    },
    "proxy": {
      "https://gold-feed.com/paid/*": {
          "target": "https://gold-feed.com/paid",
          "changeOrigin": true
      }
    }
  }
  </code></pre>
  
  <p>And then my ajax request looks like this:</p>
  
  <pre><code>const apiUrl = 'https://gold-feed.com/paid/&lt;apiID&gt;/all_metals_json_usd.php';
  
  jQuery.ajax({
    method: 'GET',
    url: apiUrl,
    success: (item) =&gt; {
      this.props.addItem(item);
    }
  });
  </code></pre>
  
  <p>But it doesn't appear to be doing anything. I'm still getting the following error:</p>
  
  <pre><code>No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access.
  </code></pre>
  
  <p>I essentially have the same issue as documented <a href="https://www.reddit.com/r/reactjs/comments/4xury9/react_webpack_and_api_calls/" rel="noreferrer">here</a> where he is trying to create a proxy to access the Steam api.</p>
  
  <p>And just a side note, I believe the create-react-app project that I'm using is piggybacking off of webpack.</p>