0

I built my first full-stack app, with an Express back end and React front end, contained in the same project folder (see GitHub repo). The front end is contained in a folder called client. I deployed the app from the root directory -- on the deployed site, it just says "Cannot GET /." The package.json in the front end portion has a proxy field that proxies requests to the back end. When I open the project on localhost, everything works correctly. Any pointers would be greatly appreciated.

nCardot
  • 5,992
  • 6
  • 47
  • 83

1 Answers1

1
 "scripts": {
    "start": "node server",
    "heroku-postbuild": "cd client && npm install && npm run build"
  },

Try that fix in your backend package.json part. First, you want to get the backend set and then Heroku needs React to run. Heroku has some quirks to it.

  • Thanks for the suggestion -- the "start": "node server" part was already in scripts, but I added "heroku-postbuild": "cd client && npm install && npm run build" and redeployed and it still just said Cannot GET / – nCardot Nov 18 '19 at 04:33
  • 1
    Ok---so if it works locally but not on Heroku even after my suggestion, this is probably it: on `SETTINGS` on your Heroku deployment project page, go to the `CONFIG VARS` spot and manually type in your variables and values from your `config/server.js` file. Add the `process.env` stuff on Heroku and see if that works. –  Nov 18 '19 at 04:46
  • That was it, had to add the config vars, also had to add this in my server.js file for it to work: if (process.env.NODE_ENV) { app.use(express.static('client/build')); const path = require('path'); app.get('*', (req, res) => { res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html')); }); } Many thanks! – nCardot Nov 18 '19 at 04:59