使用CI/CD在Heroku上部署Anguilarjs应用程序 [英] Deploying an Anguilarjs app on Heroku using CI/CD
问题描述
我基于典型的目录结构制作了一个小的Angularjs,该目录结构将源存储在al的"src"目录中并部署到"dist"目录中.因此,我在github页面中将代码部署在本地服务器上没有问题.我已经建立了一个CodeShip CI/CD实例,它可以很好地运行测试并进行部署,但是却无法成功进行.
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.
该代码已部署到heroku,但是我找不到使它在heroku内部运行的方法.
The code is being deployed to heroku, but I can't find the way to make it work inside heroku.
我已经制作了一个Procfile:
I already made a Procfile:
web: node node_modules/gulp/bin/gulp build
web: node server.js
还有基本的servers.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 +' ++');
});
当然,我已经将express添加到了我的节点包中.实际上,它在我的本地主机(Linux和Windows)上可以正常工作
Of Course I already added express to my node package. It actually works fine in my localhost (Linux and Windows)
在Heroku日志上,没有太多信息,我怀疑我无法让express表达出正确的路径,所以它崩溃了.
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(使用节点6.10.2)
CODESHIP (using node 6.10.2)
推荐答案
要运行构建步骤,您可以使用 npm脚本
来完成,如下所示:
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"
}
然后您的 Procfile
可以很简单-
web: npm start
就错误而言,很难说,因为我没有完整的错误要看.确保您的 server.js
文件在正确的位置,并且您有一个 package.json
文件,其中列出了所有依赖项.
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.
这篇关于使用CI/CD在Heroku上部署Anguilarjs应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!