简体   繁体   English

Heroku Node.js 应用程序在本地运行,但在部署时不运行

[英]Heroku Node.js App Works Locally but not when deployed

I have a MEAN Stack Heroku app that was running just fine.我有一个运行良好的 MEAN Stack Heroku 应用程序。 But then I added a new function:但后来我添加了一个新功能:

app.get('/userCreated/:id', function(req, res) {

if (req.cookies.userCreated == req.params.id) { 
    res.send(true);
}
else {
    res.send(false);
}

});

And now I get a 503 (Service Unavailable) error upon loading the app.现在我在加载应用程序时收到 503(服务不可用)错误。 Anyone have an idea why this might be?任何人都知道为什么会这样?

I'm using Angular and $http.get() to access this Express.js function...我正在使用 Angular 和 $http.get() 来访问这个 Express.js 函数......

Edit: here is my client side Angular code that is making a call to the server:编辑:这是我的客户端 Angular 代码,它正在调用服务器:

var deferred = $q.defer();
function thisUserCreated(id) {
$http.get('/userCreated/' + id).success(function(data) {
deferred.resolve(data);
// returns boolean indicating whether the current user has the proper cookie
// saying this user created the given group
});
return deferred.promise;
};

Well, I actually figured it out.嗯,我真的想通了。 Turns out I hadn't listed all my dependencies in my package.json.结果我没有在 package.json 中列出我所有的依赖项。

Lesson here: when installing node packages always use --save教训:安装节点包时总是使用--save

Or you're gonna have a bad time.否则你会过得很糟糕。

Nothing in that block of code is inherently broken.该代码块中的任何内容都没有本质上被破坏。

Just check the logs to see what's giving you errors:只需检查日志,看看是什么给了你错误:

heroku logs --tail

Try to recompile ( ng build -prod ) Angular side and deploy it again.尝试重新编译( ng build -prod )Angular 端并再次部署它。 Also watch MEAN Stack Front To Back [Part 10] - App Deployment to Heroku另请观看MEAN Stack Front To Back [第 10 部分] - 应用部署到 Heroku

I dealt with this problem in many different forms with Node/Heroku exit status 1 and status H10 etc. etc.. I searched and search tried everything from purging the node cache to rolling everything back via git and starting again.我用 Node/Heroku 退出状态 1 和状态 H10 等以许多不同的形式处理了这个问题。我搜索和搜索尝试了从清除节点缓存到通过 git 回滚所有内容并重新开始的所有方法。 It seemed as though my node_modules kept updating somewhere and I would jump from getting errors to functioning locally to crashing once deployed.好像我的 node_modules 一直在某个地方更新,我会从出错跳到本地运行,再到部署后崩溃。 The only thing that finally worked was to "not check in generated directories" in my .gitignore file, which if works for others in this situation seems like a stupid and obvious solution.唯一最终有效的是在我的 .gitignore 文件中“不检查生成的目录”,如果在这种情况下对其他人有效,这似乎是一个愚蠢而明显的解决方案。 The different troubleshooting steps can be found here https://devcenter.heroku.com/articles/troubleshooting-node-deploys可以在此处找到不同的故障排除步骤https://devcenter.heroku.com/articles/troubleshooting-node-deploys

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM