title: React server with Node and Proxy API requests
body: <p>I'm relatively new to React, and trying to deploy an application to an Openshift environment. The app consists of a React JS front-end which makes API calls to a nodejs back end restful api. That's the idea at least.</p>
  
  <p>Most of the ways I've found suggest using docker, but I have no idea where to start with that. The <code>create-react-app</code> documentations gives an example of an Node/Express server to render the index.html, which I am much more familiar with and have got working, but I can't seem to set a proxy to route the api calls to the back-end.</p>
  
  <p>I initially tried setting the proxy in the package.json, but that didn't work. I then found <code>express-http-proxy</code> which looked promising, but can't get it to work.</p>
  
  <p>My front end server looks like this:</p>
  
  <pre><code>const express = require('express');
  const path = require('path');
  const app = express();
  const proxy = require('express-http-proxy');
  const PORT = process.env.OPENSHIFT_NODEJS_PORT || 8080;
  const API_PROXY_URL = process.env.APIURL
  
  app.use(express.static(path.join(__dirname)));
  
  app.use('/api', proxy(API_PROXY_URL));
  
  app.get('/*', (req, res) =&gt; {
    res.sendFile(path.join(__dirname, 'index.html'));
  });
  
  app.listen(PORT, () =&gt; {
    console.log(`Server Started on port ${PORT}`);
    console.log(`Proxy in use of ${API_PROXY_URL}`);
  });
  </code></pre>
  
  <p>I have a generic api function which is making the calls using axios:</p>
  
  <pre><code>export function apiCall(method, path, data) {
    return new Promise((resolve, reject) =&gt; {
      return axios[method.toLowerCase()](path, data)
        .then(res =&gt; {
          return resolve(res.data);
        })
        .catch(err =&gt; {
          return reject(err.response.data.error);
        });
    });
  }
  </code></pre>
  
  <p>For example, my when I try and sign in it is trying to do a <code>post</code> call to <code>&lt;&lt;REACTURL&gt;&gt;/api/auth/signin</code> when I want it to send to <code>&lt;&lt;APIURL&gt;&gt;/api/auth/signin</code>.</p>
  
  <p>I feel I'm missing something really obvious.</p>