客户端使用create-react-app构建,后端使用express,node.js和MongoDB构建。它可以在本地运行,但是当我部署到Heroku时,只有后端可以运行...
index.js
app.use(express.static(path.join(__dirname,'client','build')));
+app.get('/',function(req,res) {
-app.get('/*',function (req,res) {
res.sendFile(path.join(__dirname,'build','index.html'));
});
});
}
服务器端的package.json
"scripts": {
"start": "node index.js","heroku-postbuild": "cd client && npm install --only=dev && npm install && npm run build"
},
package.json在客户端
"scripts": {
"start": "react-scripts start","build": "react-scripts build","test": "react-scripts test","eject": "react-scripts eject"
},"proxy": "http://localhost:5000",
此外,我在MongoLab上的猫鼬工作正常并将其添加到Heroku 顺便说一句,当我推到Heroku时,似乎一切正常。我的意思是,它导航到客户端并安装并构建软件包