I have a problem, it's an API with NodeJS and the client with Ionic (code available here as well).
// SERVICES.JS
angular.module('app.services', [])
.factory('loginService', function($http){
return{
print: function() {
return $http.get('http://EXTERNALURL:3000/print').then(function(res) {
return res.data;
})
},
login: function(post) {
return $http({
url: 'http://EXTERNALURL:3000/login',
method: 'POST',
data: post,
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).success(function (data, status, headers, config) {
console.log(data);
}).error(function (data, status, headers, config) {
console.log(status);
});
}
}
})
// ROUTES.JS en servidor externo
app.post('/login', function(req, res){
console.log(req.body)
AM.manualLogin(req.body['user'], req.body['pass'], function(e, o){
if (!o){
res.status(400).send(e);
} else{
req.session.user = o;
if (req.body['remember-me'] == 'true'){
res.cookie('user', o.user, { maxAge: 900000 });
res.cookie('pass', o.pass, { maxAge: 900000 });
}
res.status(200).send(o);
}
});
});
The problem is that when sending the data from postman on the server by the line console.log(req.body)
shows them to me like this:
{"user":"[email protected]","pass":"Seighei7"}
Which is the correct way, but when sending them from Ionic with the client that armes in services.js it shows it like this:
{ '{"user":"[email protected]","pass":"Seighei7"}': '' }