Hello,
I'm trying to run simple application on heroku, but it throws error, and I cannot figure out what the problem is.
var port = process.env.PORT || 80;
var Server = Hapi.createServer('localhost', port);
Error:
/restful_api/node_modules/hapi/node_modules/hoek/lib/index.js:382
throw new Error(msgs.join(' ') || 'Unknown error');
Error: Bad server constructor arguments: duplicated arg type: string (values: localhost, 5000)
Here is a working express app from heroku.
var express = require("express");
var app = express();
app.use(express.logger());
app.get('/', function(request, response) {
response.send('Hello World!');
});
var port = process.env.PORT || 5000;
app.listen(port, function() {
console.log("Listening on " + port);
});
What do you think the problem is?
HAPI is expecting an integer for the port but it looks like process.env.PORT
is a string in this instance.
Try this -
var port = parseInt(process.env.PORT) || 5000
var server = new Hapi.createServer('localhost', serverConfig);
//set the port
server._port = process.env.PORT || 8001;
// Start the server
server.start();
On Wed, Sep 4, 2013 at 6:41 AM, Jamal Soueidan [email protected]:
Hello,
I'm trying to run simple application on heroku, but it throws error, and I
cannot figure out what the problem is.´´´javascript
var port = process.env.PORT || 80;
var Server = Hapi.createServer('localhost', port);
´´´Error:
/restful_api/node_modules/hapi/node_modules/hoek/lib/index.js:382
throw new Error(msgs.join(' ') || 'Unknown error');Error: Bad server constructor arguments: duplicated arg type: string
(values: localhost, 5000)Here is a working express app from heroku.
´´´javascript
var express = require("express");
var app = express();
app.use(express.logger());app.get('/', function(request, response) {
response.send('Hello World!');
});var port = process.env.PORT || 5000;
app.listen(port, function() {
console.log("Listening on " + port);
});
´´´What do you think the problem is?
—
Reply to this email directly or view it on GitHubhttps://github.com/spumko/hapi/issues/1043
.
This works, but Heroku never start my app...?
foreman start
16:30:30 web.1 | started with pid 18135
...it hangs at started with pid...
Do you think this is related to hapi framework?
I haven't used Heroku before, what is supposed to happen next?
Is something else supposed to display in the console? Can you ping the
server?
On Wed, Sep 4, 2013 at 3:30 PM, Jamal Soueidan [email protected]:
This works, but Heroku never start my app...?
foreman start
16:30:30 web.1 | started with pid 18135...it hangs at started with pid...
Do you think this is related to hapi framework?
—
Reply to this email directly or view it on GitHubhttps://github.com/spumko/hapi/issues/1043#issuecomment-23793654
.
Here is a sample app of running hapi on heroku: https://github.com/wpreul/hapi-heroku
Not knowing anything about Heroku and not knowing whether your server is
actually running on the PID given as output, i'm not sure if I can be much
more help.
If you have console access you could try ps -A and see if the PID is listed
and what process it is running - should be node. Are you writing anything
to console after the server has started?
Have you tried running the example you linked to?
On Wed, Sep 4, 2013 at 3:51 PM, Wyatt [email protected] wrote:
Here is a sample app of running hapi on heroku:
https://github.com/wpreul/hapi-heroku—
Reply to this email directly or view it on GitHubhttps://github.com/spumko/hapi/issues/1043#issuecomment-23795412
.
Thank you very much milo for your help.
But I tried the example on heroku and it works, so now I'm trying to figure out what the problem is with my app :)
@jamalsoueidan - Did you solve the issue? I'm facing something similar at the moment.
I ended up needing to switch from host: 'localhost' to host: '0.0.0.0'.
I found this to be working server.connection({port : process.env.PORT ||3000 })
app.listen(process.env.PORT || 5000);
This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.
Most helpful comment
I found this to be working
server.connection({port : process.env.PORT ||3000 })