I am working on a app where I am using Hapijs/Nodejs with AngularJS
here is the Nodejs part
server.route({
method: 'POST',
path: '/login',
handler: function(request, reply) {
USER: request.payload.user,
PWD: request.payload.password,
PLANTA: request.payload.planta,
PLANGROUP: request.payload.plantgroup,
START_DATE: request.payload.startDate
}
});
now the Angular part
.factory('LoginService', function($http, $q) {
var defer = $q.defer();
return {
login: function() {
$http.post('http://localhost:8000/login', {
user: 'USRCP_HW',
password: 'usrcp2012',
planta: '6000',
plantroup: 'E10',
startDate: '2014-11-26'
}).success(function(data) {
console.log(data);
return data;
}).error(function(data, status){
console.log(data, status);
defer.reject(data);
});
return defer.promise;
}
}
});
and the Login Controller
.controller('LoginCtrl', function($rootScope, $scope, $stateParams, LoginService) {
$scope.login = function(data) {
console.log(data);
};
});
all I need is to log the data, but I am getting undefined.
and if in the controller I do
$scope.login = function(data) {
console.log(data);
LoginService.login(data).then(function() {
console.log(data);
})
};
I get this in the browser console
OPTIONS http://localhost:8000/login
XMLHttpRequest cannot load http://localhost:8000/login. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:8000' is therefore not allowed access. The response had HTTP status code 501.