Heroku Cannot GET /

后端 未结 8 463
梦谈多话
梦谈多话 2020-12-03 21:08

I am new to Heroku and believe I am following all of the steps outlined on Heroku\'s website to deploy via node.js – https://devcenter.heroku.com/articles/getting-started-wi

8条回答
  •  无人及你
    2020-12-03 21:51

    Make sure you have these 2 things in place:

    1. In your package.json, include heroku-postbuild line, in my case is like this, (it might change if you need to do more than one install)
            "scripts": { 
            "heroku-postbuild": "npm install --prefix client && npm run build --prefix client"
          },
    
    1. In your index.js file, add a condition for production
        if (process.env.NODE_ENV === "production"{
          app.use(express.static("build"));
          app.get("*", (req, res) => {
            res.sendFile(path.resolve(__dirname,  "build", "index.html"));
          });
        }
    

    Express will serve up production assets like our main.js file, or main.css file!

    Finally- Express looks if the request is for an asset Express will serve up the index.html file if it doesn't recognize the route

提交回复
热议问题