I'm trying to get the header with $http
, I send a response with the data and header with Node.js, x-auth is my custom header.
I can get the response.data
just fine,
but when I use response.header('x-auth')
it prints null
.
When I test the response with 'Postman' everything works properly and I get the header as expected.
I can even see the custom header in the dev tools,
this is the cors of my nodejs cors code:
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
Here is a snippet of my code:
$http({
method: 'GET',
url: 'http://localhost:3000/test'
}).then(function successCallback(response) {
console.log(response.data);
console.log(response.headers('x-auth'));
}, function errorCallback(response) {
console.log("error");
});
hope you can help me with that.