我有一个项目,有两个不同的文件夹。一个是前端,另一个是后端。我想将这两个文件夹部署在一个heroku应用程序上。
在server.js中,我有
app.get('*', (req, res) => {
return res.sendFile(path.join(__dirname, '../frontend/dist/index.html'))
})因此,当我尝试在文件夹的根目录下使用git bash部署angular.But的index.html文件时,我会收到语言未指定的错误或其他错误。我谷歌了一下这个错误,人们说这是因为我在文件夹的根目录下没有package.json文件。
我怎么能有两个不同的文件夹和两个不同的package.json,这样我就可以部署到heroku,或者我不能?解决方案是什么?
发布于 2020-08-04 23:08:08
在Node App index.js文件中,添加以下代码并将客户端代码移动到客户端目录中
app.use(express.static(path.join(__dirname, "client/build")));
app.get("*", (req, res)=>{
res.sendFile(path.join(__dirname, "client/build",'index.html'));
})在你的Package.json中
"scripts": {
"client": "cd client && yarn start",
"server": "nodemon server.js",
"build": "cd client && npm run build",
"dev": "concurrently --kill-others-on-fail \"yarn server\" \"yarn client\"",
"start": "node server.js",
"heroku-postbuild": "cd client && npm install && npm install --only=dev --no-shrinkwrap && npm run build"
}https://stackoverflow.com/questions/63249476
复制相似问题