【发布时间】:2018-04-25 00:30:33
【问题描述】:
我在休息时设置管理员,现在当我尝试获取数据时出现此错误,即使我从服务器收到所有需要的数据:
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?
有没有办法在不更改 API 的情况下解决它?我正在根据教程进行授权,这是我的app.js:
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 = () => (
<Admin restClient={restClient} authClient={authClient}>
<Resource name="posts" list={PostList} edit={PostEdit} create={PostCreate}/>
<Resource name="users" list={UserList}/>
</Admin>
);
【问题讨论】:
-
是的,但最好的答案是在rails内部解决它
response.headers['X-Total-Count'] = '30' response.headers['Access-Control-Expose-Headers'] = 'X-Total-Count'我已经尝试过了,它不起作用。有没有办法在 reactjs 里面解决? -
尝试
Content-Range而不是X-Total-Count。 -
这几行给我一个错误
ArgumentError (wrong number of arguments (given 0, expected 2)): -
response.headers['Content-Range'] = 'posts 0-24/319'
标签: javascript ruby-on-rails reactjs http-headers admin-on-rest