Search code examples
axiosjson-server

Can't access X-Total-Count header from json-server


I am requesting data from JSON server using axios. While I can see that JSON server is returning the X-Total-Count header using Postman, but axios does not see that header. I am using http protocol, so CORS should not be an issue. What am I missing?

Here's the call to json-server:

const resp = await axios.get('/orders?_start=0&_end=100');
const orderCount = resp.headers['X-Total-Count'];

Here are the headers received (captured in Chrome Devtools). Note that X-Total-Count is missing:

enter image description here

The same HTTP call in Postman shows that X-Total-Count is returned:

enter image description here


Solution

  • Solved. I used the command line option --no-cors and axios started seeing the X-Total-Count header.