Tuesday, 8 January 2019

How to proxy with NodeJS on Heroku with free Dyno?

I have a master server on Heroku which handles redirects to other 2 apps. Basically there are 3 servers:
- master server (handles redirects)
- main app server
- secondary app server

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.
For some reason it throws an error ("Application error"), but if you refresh the page, it server the secondary app instantly.

What should I do to avoid the error message?

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);



from How to proxy with NodeJS on Heroku with free Dyno?

No comments:

Post a Comment