简体   繁体   English

在Heroku上获取请求会返回create-react-app默认页面?

[英]Get request on Heroku returns create-react-app default page?

I have a heroku backend in which I'm trying to retrieve data from: https://jabooda-homes-backend.herokuapp.com/ 我有一个heroku后端,我正在尝试从以下后端检索数据: https : //jabooda-homes-backend.herokuapp.com/

When I serve this app locally, I'm successfully able to retrieve this data; 当我在本地提供此应用程序时,我就能够成功检索此数据; however, when I do a GET request to the Heroku app via Postman, I notice that the React default HTML page gets sent back. 但是,当我通过邮递员向Heroku应用程序发出GET请求时,我注意到React默认HTML页面被发回了。 Here's an image demonstrating this: 这是演示此图像:

在此输入图像描述

Here's a snippet of the backend code that gets the data: 这是获取数据的后端代码的片段:

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)
})

(Note: I have the BE linked to MongoDB, which gets data from there; however for testing purposes I'm just trying to return the data variable I created). (注意:我将BE链接到MongoDB,MongoDB从那里获取数据;但是出于测试目的,我只是试图返回我创建的数据变量)。

Again, when I run a localhost the data comes back just fine; 再次,当我运行本地主机时,数据恢复正常。 however when I try to do this via Heroku, it fails. 但是,当我尝试通过Heroku执行此操作时,操作失败。 Does anyone know how to bypass this? 有谁知道如何绕过这个? Am I not uploading my app to Heroku correctly? 我是否无法将我的应用正确上传到Heroku? I have CORS set up on my Frontend, but I'm wondering if there's extra configurations that I need to set up in order to get this data through Heroku. 我在前端上设置了CORS,但我想知道是否需要设置其他配置才能通过Heroku获得此数据。 Any feedback would be appreciated, and if there's more info you'd like me to include, please let me know. 任何反馈将不胜感激,如果您希望我提供更多信息,请告诉我。 Thanks!! 谢谢!!

我想通了-我的后端是create-react-app中的react应用,我刚刚删除了后端应用上与react相关的所有内容...现在可以使用了!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM