Reputation: 935
I need to send an object in my response headers, but when I access it I only see [object object]
no error and nothing else.
What could possibly be the problem ?
here's how I'm sending from my server
pagination = {
'pageSize': 25,
'someInformation': 'blablabla...'
}
res.header('Access-Control-Expose-Headers', 'X-Pagination');
res.setHeader('X-Pagination', pagination);
Upvotes: 1
Views: 2252
Reputation: 12552
So header values are strings. When you pass an object
to a function that needs string it uses the Object.toString()
property and uses it.
const obj = {a:1}
obj.toString() // outputs "[object Object]"
In order to pass JSON you need to use JSON.stringify
In your case it will be:
pagination = {
'pageSize': 25,
'someInformation': 'blablabla...'
}
res.header('Access-Control-Expose-Headers', 'X-Pagination');
res.setHeader('X-Pagination', JSON.stringify(pagination));
This is current output:
Upvotes: 2