This question already has an answer here:
- How to host an AngularJS app in Heroku using Node.js WITHOUT using yeoman? 1 answer
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
CODESHIP (using node 6.10.2)