我想知道如何将我的mern应用程序部署到Azure。我已经搜索了好几天了,这让我很沮丧。当我构建我的应用程序时,它显然只构建了客户端。我如何上传我的整个项目到Azure,并运行客户端以及服务器端的应用?
我想避开Heroku,直接从Azure运行我的项目。
有什么工具可以用于构建吗?
事先非常感谢!
发布于 2019-07-10 23:49:57
为了使一个MERN应用程序在Azure上工作,你必须配置你的应用程序来显示你的静态反应构建通过快递。
编辑您的快递server.js
并添加以下内容:
const path = require("path"); // on top
// Serve Static assests if in production
if (process.env.NODE_ENV === "production") {
app.use(express.static("client/build")); // change this if your dir structure is different
app.get("*", (req, res) => {
res.sendFile(path.resolve(__dirname, "client", "build", "index.html"));
});
}
然后,将此脚本行添加到快递package.json
中。
"scripts": {
"start": "node server.js",
"azure": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client && npm run start"
}
注意:编辑这个以满足您的目录结构。
就是这样,现在上传您的应用程序到Azure,并将您的快速端口设置为80
在环境中vars在您的Azure应用程序设置。
https://stackoverflow.com/questions/56983971
复制