我尝试从json-server获取一些数据并将其发送到express服务器,但我收到了以下错误:The response to 'getList' must be like { data : [...] }, but the received data is not an array. The dataProvider is probably wrong for 'getList' ra.notification.data_provider_error at validateResponseFormat (validateResponseFormat.ts:30:1) at useDataProvider.ts:109:1
Json服务器和标头:
server.use(cors());
const allowCrossDomain = (req, res, next) => {
res.header("Access-Control-Expose-Headers", "Content-Range");
res.header("Content-Range", "cakeData 0:20/*");
next();
};
server.use(allowCrossDomain);
server.use("/api", jsonServer.router("api/db.json"));
db.json
{
"cakeData": [
{
"id": 1,
"imageurl": "https://images.unsplash.com/photo-1674991773078-12a3eab409b2?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=627&q=80",
"name": "cake",
"description": "information about cake"
},
{
"id": 2,
"imageurl": "https://images.unsplash.com/photo-1674991773078-12a3eab409b2?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=627&q=80",
"name": "cake",
"description": "information about cake"
}
]
}
以及React管理组件:
<Admin
basename="/admin"
dataProvider={simpleRestProvider("http://localhost:3000/")}
>
<Resource
name="cakeData"
list={ProductList}
create={CreateProduct}
edit={EditProduct}
/>
</Admin>
我错过了什么?只使用json-server与中间件是工作,但当我饲料的json-server表达我得到了上述错误.作为一个旁注,我正在使用代理的React代理从端口3000到5000
1条答案
按热度按时间46qrfjad1#
找到了答案。Express返回了一个html,API调用错误。