将我的API部署到Heroku之后,我从发布请求的响应中收到一个空字符串。 该请求已完成,并在Heroku日志中发送了正确的数据,但我只收到需要将数据放在其中的空字符串。
我已将响应类型从send更改为JSON,以便将数据发送回,但仍然没有运气
express route:如果需要查看其他方法,则带有代码的git repo在这里: https://github.com/Wheaties247/hidden-bones-server
app.post('/logic/:rows/:columns',
bonelogic.tileLogic,
bonelogic.createBones,
bonelogic.placeBones,
bonelogic.addWinArray,
(req, res, next)=>{
const responceObj = {
tileLogicArray : res.locals.newLogicArray,
winArray : res.locals.bonesToGo
}
console.log("request complete", responceObj)
res.send(responceObj)
})
}
Axios请求在这里,回购可以在这里找到: https://github.com/Wheaties247/HiddenBones
const herokuURl= "https://hidden-bones-server.herokuapp.com"
const localURL = "localhost/7770"
axios
.post(`${herokuURl}/logic/${rows}/${columns}`)
.then(res => {
const {tileLogicArray, winArray} = res.data
console.log("post complete", res)
this.setState({
tileLogicArray: tileLogicArray, bonesToGo:winArray,
loading:false
})
})
.catch(err => {
console.log("there was an error in axios request", err)
//error message in console if the was an issue with the error with respective error output
})
预期结果是一个对象,该对象具有两个与数组相等的属性作为值。 相反,我得到一个空字符串