title: How to proxy with NodeJS on Heroku with free Dyno?
body: <p>I have a master server on Heroku which handles redirects to other 2 apps.
  Basically there are 3 servers:<br>
  - master server (handles redirects)<br>
  - main app server<br>
  - secondary app server   </p>
  
  <p>The code below works great for redirect, but I have a problem with the sleep of servers with free dyno. 
  When an user tries to access the secondary app, initially it wakes up the master server. When the master server wakes up, it tries to wake up the secondary app.<br>
  For some reason it throws an error ("Application error"), but if you refresh the page, it serves the secondary app instantly.    </p>
  
  <p>What should I do to avoid the error message?</p>
  
  <pre><code>const express = require('express');
  const proxy = require('http-proxy-middleware');
  
  const app = express();
  
  const port = process.env.PORT || 3000;
  const router = {
      'secondaryapp.example.com': 'https://secondaryapp.herokuapp.com'
  };
  
  app.use('/', proxy({
      target: 'https://mainapp.herokuapp.com',
      changeOrigin: true,
      router: router
  }));
  
  app.listen(port);
  </code></pre>