0

I have made a small Angularjs based on a typical directory structure that stores source on al "src" directory and deploys to a "dist" directory. So fa I haven't had problem with code being deployed on local server as in github pages. I already built a CodeShip CI/CD instance, it runs testing fine and deploys but it crushes there.

The code is being deployed to heroku, but I can't find the way to make it work inside heroku.

I already made a Procfile:

web: node node_modules/gulp/bin/gulp build
web: node server.js

And also a basic servers.js

var express = require('express');
var app = express();

// I found somewhere that process.env.PORT lets the port be set by Heroku,
// but its not working
var port = process.env.PORT || 8080;

app.use(express.static(path.join(__dirname + '/dist')));
//app.use(express.static(process.env.PWD + '/dist')); //already tried this one 

// home page route
app.get('/', function(req, res) {
    res.render('index');
});

app.listen(port, function() {
    console.log('App is running fine on port:' + port +' ++');
});

Of Course I already added express to my node package. It actually works fine in my localhost (Linux and Windows)

On Heroku log, there is no much info, I suspect that I cant make express find the correct path, so it crashes.

2017-03-29T13:58:27.459049+00:00 app[web.1]:     at Module.runMain (module.js:605:10)
2017-03-29T13:58:27.554976+00:00 heroku[web.1]: State changed from starting to crashed

HEROKU On Heroku Log

CODESHIP (using node 6.10.2) CodeShip Log

Pablo Palacios
  • 2,767
  • 20
  • 37
  • what is line 605 of module.js? 2017-03-29T13:58:27.459049+00:00 app[web.1]: at Module.runMain (module.js:605:10) – Leon Apr 06 '17 at 14:54

1 Answers1

1

To run your build step, you can do it with npm scripts like this:

"scripts": {
  "start": "node server.js",
  "test": "mocha",
  "postinstall": "node node_modules/gulp/bin/gulp build"
}

Then your Procfile can be simple like this -

web: npm start

As far as the error goes, it's hard to say because I don't have the full error to look at. Make sure your server.js file is in the right spot, and you have a package.json file that lists all of your dependencies.

Kelly J Andrews
  • 5,083
  • 1
  • 19
  • 32
  • Every things runs smooth, I mean. It works everywhere, but crashes on Heroku. I guess, I am not setting the express server to the correct path. But can't find a solution. – Pablo Palacios Apr 06 '17 at 13:31
  • 1
    It runs all the chain inside Codeship, test are ok, builds perfectly, runs node, bower,.. It gets the code to Heroku, and deploys there, up to the point it's supposed to run the express server. It's very frustrating. On the images, on the Codship log, you can see on steep 16, that it finishes deployment on heroku. It just crushes there. – Pablo Palacios Apr 06 '17 at 13:34
  • have you seen this? http://stackoverflow.com/questions/27074238/how-to-host-an-angularjs-app-in-heroku-using-node-js-without-using-yeoman – Leon Apr 06 '17 at 14:00
  • 1
    This feels like a duplicate then. I'll flag it as such. The CI/CD is working. It's just express and angular on heroku. – Kelly J Andrews Apr 06 '17 at 14:17
  • 1
    Yup, after fighting a lot. And using the explanation on the other post I managed to solve it. Indeed it was the configuration. But what helped me solving the problema, was to make a second Heroku app, and directly deploying to it, what gave me more information on the logs to find the error and fix it. So, in some way it is duplicated, but it took a few more steps to solve the error and deploy from codeship. What should I do with this post, delete, mark as duplicate or complete my response? Thanks your guide to the other post did help me. – Pablo Palacios Apr 06 '17 at 16:21
  • 1
    I flagged is as a duplicate. Codeship here doesn't really get in the way of heroku logs, but you would need to be able to go back and see those logs. I think ultimately they are the same problem. The log difficulty is worth noting for our users though. I might add this to documentation somehow. – Kelly J Andrews Apr 06 '17 at 16:31