问题
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)
回答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.
来源:https://stackoverflow.com/questions/43256181/deploying-an-anguilarjs-app-on-heroku-using-ci-cd