我正在使用https://github.com/react-boilerplate/react-boilerplate上的样板文件。问题是,当我点击API's时,它返回错误404。我不能从它设置主机的地方得到它(它总是去本地主机)。浏览器上也没有出现CORS错误。
在此之前,我正在开发create-react-app,我在package.json中简单地添加了一个“代理”属性,一切工作正常。
今天我第一次设置了这个样板,我想说它是一个令_困惑的小工具:)
发布于 2018-02-09 21:32:54
您可以像这样指定API基础url:
const API = process.env.NODE_ENV !== 'production' ? 'http://google.com' : 'http://localhost:5000'因此,在开发中,它将始终指向localhost,而在生产中,它将指向其他prod服务器。
发布于 2018-04-09 05:41:07
对于仍在搜索的用户,您只需在server/index.js中创建类似以下内容
app.get('/api/user', (req, res, next) => {
let parsedBody = JSON.parse(req.body)
res.send({ express: 'Hello From Express.' });
});在客户端向/api/user发出请求
axios.get(`/api/user`)
.then(function (response) {
console.log("/api/user response", response);
})
.catch(function (error) {
console.log(error);
});干杯
https://stackoverflow.com/questions/48704483
复制相似问题