React-admin: Error: The Content-Range header is missing in the HTTP Response.

Created on 11 Nov 2017  路  2Comments  路  Source: marmelab/react-admin

I am getting this error when I try to fetch data, even though I receive all the data needed from the server:

The Content-Range header is missing in the HTTP Response. The simple REST client expects responses for lists of resources to contain this header with the total number of results to build the pagination. If you are using CORS, did you declare Content-Range in the Access-Control-Expose-Headers header?

Is there a way to solve it without making changes to the API? I was doing authorization based on the tutorial, here is my app.js:

``const httpClient = (url, options = {}) => { if (!options.headers) { options.headers = new Headers({ Accept: 'application/json' }); } const token = localStorage.getItem('token'); options.headers.set('Authorization',Bearer ${"token"}`);
return fetchUtils.fetchJson(url, options);
}
const restClient = simpleRestClient('https://mywebsite.com', httpClient);

const App = () => (



);```

Most helpful comment

server add follow:
res.header('Access-Control-Allow-Origin', 'http://localhost:3000');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.header('Access-Control-Allow-Headers', 'Content-Type,x-access-token');
res.header('Access-Control-Allow-Credentials','true');
res.header("Access-Control-Expose-Headers", "Content-Range");

All 2 comments

Hi, and thanks for your question. As explained in the admin-on-rest contributing guide, the right place to ask a "How To" question, get usage advice, or troubleshoot your own code, is StackOverFlow.

This makes your question easy to find by the core team, and the developer community. Unlike Github, StackOverFlow has great SEO, gamification, voting, and reputation. That's why we chose it, and decided to keep GitHub issues only for bugs and feature requests.

So I'm closing this issue, and inviting you to ask your question at:

http://stackoverflow.com/questions/tagged/admin-on-rest

And once you get a response, please continue to hang out on the admin-on-rest channel in StackOverflow. That way, you can help newcomers and share your expertise!

server add follow:
res.header('Access-Control-Allow-Origin', 'http://localhost:3000');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.header('Access-Control-Allow-Headers', 'Content-Type,x-access-token');
res.header('Access-Control-Allow-Credentials','true');
res.header("Access-Control-Expose-Headers", "Content-Range");

Was this page helpful?
0 / 5 - 0 ratings

Related issues

samanmohamadi picture samanmohamadi  路  3Comments

alukito picture alukito  路  3Comments

pixelscripter picture pixelscripter  路  3Comments

rkyrychuk picture rkyrychuk  路  3Comments

ericwb picture ericwb  路  3Comments