My angularjs app is running perfectly fine on localhost on my machine. But when I deploy it to heroku, the app is showing up but some of the features, mainly the frontend to backend communication is failing. I suspect that this is because I have used http://localhost:3000 instead of my real website addess: https://mytestapp.herokuapp.com . Could somebody please let me know what I should do to get this app running on heroku? with backend communicating with the frontend to get the login/signup feature running. At the moment, when I login or signup, I get an error, as if nothing has happened.
I ran grunt build, and removed the /dist from .gitignore and have a procfile like this web: node api.js .
and my package.json file is like:
"version": "1.0.0",
"main": "Gruntfile.js",
"directories": {
"test": "test"
},
"scripts": {
"start": "nf start",
"test": "echo \"Error: no test specified\" && exit 1"
},
I have also declared a constant in my app.config.js like:
.constant('API_URL', 'http://localhost:3000/')
I use API_URL to setup my login/signup authproviders.
and in my gruntfile.js , I have the following bit as well:
connect: {
options: {
port: 9000,
// Change this to '0.0.0.0' to access the server from outside.
hostname: 'localhost',
livereload: 35729
},
livereload: {
options: {
open: true,
middleware: function (connect) {
return [
connect.static('.tmp'),
connect().use(
'/bower_components',
connect.static('./bower_components')
),
connect().use(
'/app/styles',
connect.static('./app/styles')
),
connect.static(appConfig.app)
];
}
}
},
test: {
options: {
port: 9001,
middleware: function (connect) {
return [
connect.static('.tmp'),
connect.static('test'),
connect().use(
'/bower_components',
connect.static('./bower_components')
),
connect.static(appConfig.app)
];
}
}
},
update
i am trying to implement it in this controller, but no success:
when I implement the Yoni's solution, i don't get the projectlist anymore, it shows an empty page. why is that?
'use strict';
angular.module('ModuleV11App')
.controller('ProjectlistCtrl', function ($http, $scope, API_URL, alert) {
return $http.get($rootScope.server.url + '/projectlist').success(function (projectlist) {
$scope.projectlist = projectlist;
}).error(function (err) {
alert('warning', "Unable to get projects, please login first", err.message);
})
});
however, it works, when it is like this:
return $http.get(API_URL + 'projectlist').success(function (projectlist) {