我有一个heroku后端,我正在尝试从以下位置检索数据:https://jabooda-homes-backend.herokuapp.com/
当我在本地提供此应用程序时,我就能够成功检索此数据;但是,当我通过邮递员向Heroku应用程序发出GET请求时,我注意到React默认HTML页面被发回了。这是展示此图片的图片:
以下是获取数据的后端代码的片段:
const express = require('express')
const cors = require('cors')
const app = express()
// Routes
app.use('/api', router)
router.get('/getCareerData', (req, res) => {
console.log(req)
console.log('***************************************************************************************************************************************')
console.log(res)
var data = res.json({
success: true,
data: {
"_id": {
"$oid": "5c200d53e7179a74879741fb"
},
"jobtitle": "FRAMER",
"description": "",
"requirements": [
"Measure, cut and assemble lumber with precision",
"Be able to lift and carry heavy framing lumber, sheets of plywood and other materials",
"Strong analytical and mathematical skills"
],
"updatedAt": {
"$date": "2019-02-06T22:04:42.721Z"
}
}
})
return data
// return retrieveData(Careers, req, res)
})
(注意:我将BE链接到MongoDB,MongoDB从那里获取数据;但是出于测试目的,我只是试图返回我创建的数据变量)。
同样,当我运行本地主机时,数据返回就很好了;但是,当我尝试通过Heroku执行此操作时,操作失败。有谁知道如何绕过这个?我是否无法将我的应用正确上传到Heroku?我在前端上设置了CORS,但我想知道是否需要设置其他配置才能通过Heroku获得此数据。任何反馈将不胜感激,如果您希望我提供更多信息,请告诉我。谢谢!
答案 0 :(得分:0)
我发现了-我的后端是create-react-app中的react应用,我刚刚删除了与后端应用上的react相关的所有内容...现在可以使用了!