我正在尝试将 react 应用程序部署到 azure 。我测试了我的构建运行,效果很好。当我部署应用程序时,我会看到默认的“嘿,节点开发人员”页面。然后,我尝试添加一些网站上所述的 index.js 文件,例如 https://blogs.msdn.microsoft.com/waws/2017/09/08/things-you-should-know-web-apps-and-linux/#NodeHome
但现在我收到错误...
*/home/LogFiles/2020_01_13_RD0003FF73402D_default_docker.log (https://sbwebtest.scm.azurewebsites.net/api/vfs/LogFiles/2020_01_13_RD0003FF73402D_default_docker.log)
2020-01-13T11:39:01.618020509Z 11:39:01 0|index | at Object.<anonymous> (/usr/local/lib/node_modules/pm2/lib/ProcessContainerFork.js:27:21)
2020-01-13T11:39:01.619118659Z 11:39:01 0|index | at Module._compile (internal/modules/cjs/loader.js:956:30) {
2020-01-13T11:39:01.620286813Z 11:39:01 0|index | code: 'MODULE_NOT_FOUND',
2020-01-13T11:39:01.628165973Z 11:39:01 0|index | requireStack: [ '/home/site/wwwroot/index.js' ]
2020-01-13T11:39:01.629324326Z 11:39:01 0|index | }
2020-01-13T11:39:01.649097230Z 2020-01-13T11:39:01: PM2 log: App [index:0] exited with code [1] via signal [SIGINT]
2020-01-13T11:39:01.650858410Z 2020-01-13T11:39:01: PM2 log: Script /home/site/wwwroot/index.js had too many unstable restarts (16). Stopped. "errored"
2020-01-13T11:39:01.657846830Z 11:39:01 PM2 | App [index:0] exited with code [1] via signal [SIGINT]
2020-01-13T11:39:01.659306496Z 11:39:01 PM2 | Script /home/site/wwwroot/index.js had too many unstable restarts (16). Stopped. "errored"*
我已在 VS code 中使用 azure 工具进行部署。
有人知道该怎么做吗?
最佳答案
如果您基于 Windows 操作系统,此屏幕截图将告诉您如何修复它:
如果您基于Linux操作系统,有两种方法可以解决此问题。
第一种方法:
此方法的前提是你有 Node.js 环境并安装了 npm 工具。
1.在site/wwwroot下添加一个文件名index.js。
index.js:
var express = require('express');
var server = express();
var options = {
index: 'index.html' //Fill path here.
};
server.use('/', express.static('/home/site/wwwroot', options));
server.listen(process.env.PORT);
2.安装 express :
在wwwroot目录下运行此命令,
npm install -save express
3.重新启动您的应用服务并等待几分钟。
第二种方法:
1.在根目录下创建.htaccess
文件。
.htaccess
文件:
DirectoryIndex public_html/index.php
2.重新启动您的网络应用程序并等待几分钟。
这是我的网络应用程序的结构:
成功:
如果您有更多疑问,请告诉我。
关于reactjs - 如何将 React 应用程序部署到 azure 并更改默认页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59716560/