0

I'm about to finish an Ionic2 application that uses socket.io. I use to run (locally) my app with ionic serve (client side) in one terminal and with node index.js (server side) on another terminal. (index.js file is inside my ionic2 project folder). Now I want to try this out with Heroku.

These are the server side files I have:

My index.js file looks like this:

var io = require('socket.io'),
    http = require('http'),
    server = http.createServer(),
    io = io.listen(server);
...
...
my real code here
...
...
server.listen(process.env.PORT || 3000, function(){
  console.log('Server started, listening on' + process.env.PORT);
});

along with index.js I created (npm init) a package json which looks like this:

{
  "name": "myApplication",
  "version": "0.2.5",
  "description": "just a server",
  "engines": {
    "node": "4.2.6"
  },
  "main": "index.js",
  "scripts": {
    "start": "node index.js"
  },
  "dependencies": {
    "ejs": "2.4.1",
    "express": "4.13.3",
    "socket.io": "^1.5.0"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/xxxxxxxxx"
  },
  "keywords": [
    "node",
    "heroku",
    "express"
  ],
  "license": "MIT"
}

Procfile content is this: web: node index.js

While app.json holds this:

{
  "name": "MyAppServer",
  "description": "",
  "repository": "https://github.com/xxxxxxxx",
  "logo": "http://node-js-sample.herokuapp.com/node.svg",
  "keywords": ["node", "express", "static"],
  "image": "heroku/nodejs"
}

Before pushing all this stuff into github repo I've done npm install so I got node_modules folder. So I pushed everything on a github repo and then heroku login, heroku create. Finally git push heroku master returned me Build succeeded but now, when I do heroku open I see a page which says Application Error.

These are the warnings I get when I do heroku logs:

    2016-10-31T14:00:05.707656+00:00 heroku[web.1]: Idling
    2016-10-31T14:00:05.708289+00:00 heroku[web.1]: State changed from up to down
    2016-10-31T14:00:08.267802+00:00 heroku[web.1]: Stopping all processes with SIGTERM
    2016-10-31T14:00:09.009402+00:00 heroku[web.1]: Process exited with status 143
    2016-10-31T16:34:38.691494+00:00 heroku[web.1]: State changed from down to starting
    2016-10-31T16:34:40.170397+00:00 heroku[web.1]: Starting process with command `node index.js`
    2016-10-31T16:34:42.503141+00:00 app[web.1]: Server started, listening on39519
    2016-10-31T16:34:43.875418+00:00 heroku[web.1]: State changed from starting to up

2016-10-31 heroku[router]: at=error code=H12
 desc="Request timeout" method=GET path="/" host=xxxx-xxxx-xxxx.herokuapp.com 
request_id=20f79d56-4e51-4ace-af50-9b332e9778a1 fwd="my IP address here" dyno=web.1 connect=0ms 
service=30000ms status=503 bytes=0
splunk
  • 6,435
  • 17
  • 58
  • 105
  • I see you're using http, but just to make sure, you're not using https to create a server. Checkout this possibly related issue: http://stackoverflow.com/questions/17631536/https-node-js-application-on-heroku – R.A. Lucas Oct 31 '16 at 17:55
  • Are there any more heroku logs, because the last state describes the server is running. When you do the deploy the previous/running instance gets the sigterm signal to close down the app, after that the new app is brought up. – Risto Novik Oct 31 '16 at 19:52
  • @RistoNovik Yes there are more logs, I've updated the logs list in the question – splunk Oct 31 '16 at 20:08
  • 1
    Thank you this seems to give more information, the route at `/` has been accessed and as you can see it received request timeout error, the most common case is that the server never responds, make sure to send back something in response otherwise you receive error. At least in the route /, response.json({ code: 200 });. More about the express response object http://expressjs.com/en/4x/api.html#res – Risto Novik Oct 31 '16 at 20:13
  • @RistoNovik thank you I solved it, the error diseappeared. I'd like to ask you another thing: On my client side I have this line which should make the connection to the server: this.socket = io('https://.herokuapp.com:WHICH_PORT_HERE???'); I don't know what port should I insert in that statement. I tried with 3000 but it seems it doesn't work. Everytime I try to see on which port my heroku app is running on (with 'heroku run printenv' command ) I get a different value. – splunk Nov 01 '16 at 09:02
  • Yes heroku uses usually different port for the server, in client try to connect url without port. – Risto Novik Nov 01 '16 at 10:09

0 Answers0