[英]How do I deploy an react app to azure and change the default page
我正在尝试将 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 代码中使用 azure 工具进行了部署。
有谁知道该怎么做?
这种方法的前提是你有 Node.js env 并安装了 npm 工具。
1.在site/wwwroot下添加文件名index.js。
索引.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.安装快递:
在 wwwroot 目录下运行此命令,
npm install -save express
3.重新启动您的应用服务并等待几分钟。
1.在根目录下创建一个.htaccess
文件。
.htaccess
文件:
DirectoryIndex public_html/index.php
2.重新启动您的网络应用程序并等待几分钟。
这是我的网络应用程序的结构:
成功:
如果您有更多疑问,请告诉我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.