title: Redirect to external URL from express server via GET request from React App
body: <p>Suppose I have two servers A and B:<br>
  <strong>A</strong> -> React App server<br>
  <strong>B</strong> -> API Server (in my case Node with Express)<br>
  <strong><em>Both of which I have control.</em></strong>  </p>
  
  <p>I have CORS enabled on server B, and on development <strong>am using proxy</strong> in my client app's <em>package.json</em> to query the API server.  </p>
  
  <p>Now the problem is when I send a GET request from server A to the API server and ask it to do a redirect to another external URL I get a CORS error in my React App.  </p>
  
  <p>But, when I make a GET request to the API server via Postman I am redirected.
  I understand that it happens because the react app server is not registered with CORS while the API server is.  </p>
  
  <p><em>And this issue can be mitigated if both the applications are on the same server. Correct me if I am wrong?</em>  </p>
  
  <p>Am currently doing a workaround by making a GET request to the API server, getting the redirect URL as a response and doing a redirect on the client side.  </p>
  
  <p>Now my question is, whether there is any other possible way in which I don't have to get the redirect url as a response/ put both applications on same server and instead do a redirect straightaway?  </p>
  
  <p>I want the request flow to be:<br>
  React App [<strong><em>app.com</em></strong>] ----<strong>GET</strong>----> Api server[<strong><em>api.app.com</em></strong>]) ----<strong>REDIRECT</strong>----> <strong>External URL</strong>  </p>
  
  <h1><strong>My current implementation:</strong></h1>
  
  <p><strong>API Snippet</strong>  </p>
  
  <pre><code>try {
      let url = await Urls.findOne({ shortCode: shortCode });
  
      if(!url) {
          // Send 404
          return res.status(404).send({ status: "NOT_FOUND" });
      }
      // Redirect to original URL
      //res.redirect(url.longUrl);
      return res.status(200).send({ status: "FOUND", url: url.longUrl });
  }
  catch(error) {
      console.log(error);
      return res.status(500).send({ status: "FAILED" });
  }
  </code></pre>
  
  <p><strong>Client Side</strong></p>
  
  <pre><code>componentDidMount() {
      let id = this.props.match.params.id;
  
      axios.get(`/api/${id}`)
          .then(response =&gt; {
              window.location.replace(response.data.url);
          })
          .catch(error =&gt; {
              this.setState({ displayError: true, errorType: error.response.data.status })
          });
  }
  </code></pre>