你能告诉我如何获得我的json api吗?表示app.get('/ *')和api CORs问题
server.js
app.get('/*', function(req, res) {
res.sendFile(path.join(__dirname, 'public', 'index.html'));
})
app.get('/api', function(req, res) {
res.header()
res.json({'message' : 'hi this is my json obj'});
})
App.js
class App extends React.Component {
componentDidMount() {
// let foo;
axios.get('http://localhost:3000/api')
.then(res => {
console.log(res.data);
res.data.message;
})
.catch(err => {
console.log(err);
})
}
出于某种原因,这样我可以得到反应路由器来访问本地主机:3000 /仪表板只需输入查询URL字段罚款。它一直在返回html字符串。我可以改变什么,以便我可以接收json对象而不是html字符串?
什么是返回?并且确保它会向你的路由请求 –
它在app.get('/ api'',交换路径位置 – adeneo
什么html之前命中'app.get('/ *''字符串它实际返回? –