title: Serving multiple react apps with client-side routing in Express
body: <p>I have different software products for one single service, which needs to be deployed to a single server. The clients are built with react, with a build setup by create-react-app, while the server runs Node.js and Express. </p>
  
  <p>When I serve a single application from the server it is done the following way:</p>
  
  <pre><code>// App.js
  // ...
  // Entry point for data routes (API)
  app.use('/data', indexRoute);
  
  if(process.env.NODE_ENV !== 'development') {
    app.use(express.static(path.join(__dirname, 'build-client')));
  
    app.get('/*', function(req, res) {
      return res.sendFile(path.resolve( __dirname, 'build-client' , 'index.html'));
    });
  }
  </code></pre>
  
  <p>I want to be able to serve multiple apps from the server. How should I do that?</p>
  
  <p>What I tried is to wire in different static paths for the assets and separate the clients with different names, although it did not work. Like this:</p>
  
  <pre><code>// App.js
  // ...
  // Entry point for data routes (API)
  app.use('/data', indexRoute);
  
  if(process.env.NODE_ENV !== 'development') {
    app.use(express.static(path.join(__dirname, 'build-client')));
    app.use(express.static(path.join(__dirname, 'build-admin')));
  
    app.get('/client/*', function(req, res) {
      return res.sendFile(path.resolve( __dirname, 'build-client' , 'index.html'));
    });
    app.get('/admin/*', function(req, res) {
      return res.sendFile(path.resolve( __dirname, 'build-client' , 'index.html'));
    });
  }
  </code></pre>
  
  <p>I have also tried to do it this way, but Express throw Error: No default engine was specified and no extension was provided:</p>
  
  <pre><code>if(process.env.NODE_ENV !== 'development') {
    // Admin paths
    app.use('/admin', express.static(path.join(__dirname, 'build-admin')));
    app.get('/admin/*', function(req, res) {
      return res.sendFile(path.resolve( __dirname, 'build-admin' , 'index.html'));
    });
  
    // Site paths
    app.use('/', express.static(path.join(__dirname, 'build-client')));
    app.get('/*', function(req, res) {
      return res.sendFile(path.resolve( __dirname, 'build-client' , 'index.html'));
    });
  }
  </code></pre>
  
  <p>How could I accomplish this or something similar?</p>