Search code examples
javascriptnode.jsreactjsherokuheroku-api

Generate a production build fullstack app in react - heroku


I developed full stack app in react. I deployed my app with heroku, and the front side of the app not working https://jovelapp2.herokuapp.com - message "Cannot get /" https://jovelapp2.herokuapp.com/api/persons - but my backend route works fine when i run the command “node index.js” (the whole app)

I ran the command "npm run build" then i copied the build folder to my backend project, i tested the app locally and ran the command node index.js and everything on my local machine works fine...

This is what i get from the logs :

2022-11-05T20:26:20.838620+00:00 app[web.1]: GET /api/persons {}
2022-11-05T20:26:20.838656+00:00 app[web.1]: GET /api/persons 200 223 - 0.296 ms
2022-11-05T20:28:37.129945+00:00 app[web.1]: GET /api/presons {}
2022-11-05T20:28:37.129966+00:00 app[web.1]: GET /api/presons 404 150 - 0.186 ms
2022-11-05T20:28:37.128672+00:00 heroku[router]: at=info method=GET path="/api/presons" host=jovelapp2.herokuapp.com request_id=9b2d2299-4d6f-468f-beb1-3505041277ee fwd="77.137.65.235" dyno=web.1 connect=0ms service=1ms status=404 bytes=426 protocol=https
2022-11-05T20:28:39.432076+00:00 heroku[router]: at=info method=GET path="/" host=jovelapp2.herokuapp.com request_id=00f7b3bd-fb30-4dfd-a38d-d8cc41308bb1 fwd="77.137.65.235" dyno=web.1 connect=0ms service=1ms status=404 bytes=415 protocol=https
2022-11-05T20:28:39.433257+00:00 app[web.1]: GET / {}
2022-11-05T20:28:39.433278+00:00 app[web.1]: GET / 404 139 - 0.169 ms

Please tell me if you need some piece from my code to understand it better.

Thanks in advance !


Solution

  • It seem your project was deployed successfully.

    If you want to handle the GET request in path "/" you need to explicitly create a handler for it.

    Looks like Express.js, so something that like this should do the job:

    const app = express();
    app.get('/', (req, res) => {
        res.send('this is the root path!')
    });