reactjs - 如何将 React 应用程序部署到 azure 并更改默认页面

标签 reactjs azure

我正在尝试将 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 操作系统,此屏幕截图将告诉您如何修复它:

enter image description here

如果您基于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.重新启动您的网络应用程序并等待几分钟。


这是我的网络应用程序的结构:

enter image description here

成功:

enter image description here

如果您有更多疑问,请告诉我。

关于reactjs - 如何将 React 应用程序部署到 azure 并更改默认页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59716560/

相关文章:

.net - transient 故障处理应用程序 block 是否处理当前连接到联合数据库的连接?

Azure - 启动多个 Web 角色项目时出错

javascript - 如何在react中不添加url的情况下导航到特定路线

azure - 我可以使用同一个 Redis 实例来存储来自多个应用程序的 session 吗?

javascript - React Redux 如何处理循环中的连续变化

javascript - 如果 true 设置属性,否则在 JSX 中设置 className

asp.net-mvc - 在 ASP.NET MVC 5 中使用远程 Redis 配置 OutputCache

azure - 识别列中的部分文本并在 Azure 数据流中创建新列?

reactjs - 如何访问 Gatsby 模板组件中的上下文变量?

javascript - react render 正在使用旧的和新的状态值,而不仅仅是新值