Port timeout deploying Loopback app to Heroku
Asked Answered
E

2

10

I deployed an Loopback app to Heroku, but it keeps crashing with error

Web process failed to bind to $PORT within 60 seconds of launch

I know it could be connected to the dynamic port of Heroku, so I set my port to the process environment one doing

app.start = function () {
  // start the web server

  var port = process.env.PORT || 3000;

  app.set('port', port);

  app.use(loopback.static(path.resolve(__dirname, '../client')));
  app.use(loopback.static(path.resolve(__dirname, '../.tmp')));

  return app.listen(function () {
    app.emit('started');
    console.log('Web server listening at: %s', app.get('url'));
  });
};

but this didn't fix the issue.
Any idea?

Elfriedeelfstan answered 26/10, 2015 at 19:43 Comment(1)
You didn't bind any port. Try app.listen(app.get('port'), ...)Aikens
N
1

You can force Heroku to use provided port by modifying the code as provided in the documentation. If you can't relate to api docs, don't worry it's because javascript is flexible.

app.start = function () {
  // start the web server

  var port = process.env.PORT || 3000;

  app.use(loopback.static(path.resolve(__dirname, '../client')));
  app.use(loopback.static(path.resolve(__dirname, '../.tmp')));

  return app.listen(port, function () {
    app.emit('started');
    console.log('Web server listening at: %s', app.get('url'));
  });
};
Niggling answered 29/10, 2015 at 12:34 Comment(0)
I
0

I had thesame problem. I solved it by adding an environment variable HOST=0.0.0.0 in my Heroku app.

Heroku app environment variables

Isochronism answered 27/10, 2018 at 22:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.