简体   繁体   中英

Heroku Node.js App Works Locally but not when deployed

I have a MEAN Stack Heroku app that was running just fine. 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. Anyone have an idea why this might be?

I'm using Angular and $http.get() to access this Express.js function...

Edit: here is my client side Angular code that is making a call to the server:

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.

Lesson here: when installing node packages always use --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. Also watch MEAN Stack Front To Back [Part 10] - App Deployment to 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. It seemed as though my node_modules kept updating somewhere and I would jump from getting errors to functioning locally to crashing once deployed. 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. The different troubleshooting steps can be found here https://devcenter.heroku.com/articles/troubleshooting-node-deploys

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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