title: NodeJs Express Server to Proxy and Host Static Content
body: <p>I am trying to create a nodejs server with expressjs that serves my static react content.  How do I implement to say if you are a proxied path, proxy else return index.html.  Current code is below:</p>
  
  <pre><code>const path = require('path');
  const express = require('express');
  const app = express();
  const publicPath = path.join(__dirname, 'build');
  var proxy = require('http-proxy-middleware');
  
  app.use(express.static(publicPath));
  
  app.use('/pcs', proxy('/pcs',
      {
        target: '&lt;target&gt;',
        changeOrigin: true,
        pathRewrite: {'^/pcs': ''},
        hostRewrite: 'localhost:3000',
        protocolRewrite: 'http'
      }));
  
  app.get('*', (req, res) =&gt; {
    res.sendFile(path.join(publicPath, 'index.html'));
  });
  
  app.listen(3000, () =&gt; {
    console.log('Server is up!');
  });
  </code></pre>