React App 未在 azure 应用服务中启动 [英] React App not starting in azure app service

查看:21
本文介绍了React App 未在 azure 应用服务中启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将一个简单的 React 应用部署到 azure 应用服务,但它无法启动:

I've deployed a simple react app to azure app service and it won't start:

如何让应用程序运行 index.html?

How do I get the app to run index.html?

推荐答案

如果您部署到 Node Linux Web App,默认文档将是 hostingstart.html 位于 /home/site/wwwroot/.

If you deployed to a Node Linux Web App the default document would be hostingstart.html located in /home/site/wwwroot/.

根据 这个:

当你创建一个 Node.js 应用程序时,默认情况下,它会使用hostsstart.html 作为默认文档,除非您将其配置为寻找不同的文件.您可以使用 JavaScript 文件来配置您的默认文档.在根目录中创建一个名为 index.js 的文件您网站的文件夹

When you create a Node.js app, by default, it's going to use hostingstart.html as the default document unless you configure it to look for a different file. You can use a JavaScript file to configure your default document. Create a file called index.js in the root folder of your site

所以转到您的 ssh 终端,导航到 /home/site/wwwroot.使用以下代码在那里创建 index.js:

So go to your ssh terminal, navigate to /home/site/wwwroot. Create index.js there with the following code:

var express = require('express');
var server = express();
var options = {
index: 'index.html'
};
server.use('/', express.static('/home/site/wwwroot', options));
server.listen(process.env.PORT);

注意:一定要在这个文件夹中运行 npm install --save express 否则你的应用服务会在启动时崩溃

NOTE: Be sure to run npm install --save express also in this folder else your app service will crash on startup

重新启动,它会将 index.html 配置为您的应用程序的默认文档.

Restart, it will configure index.html as the default document for your app.

这篇关于React App 未在 azure 应用服务中启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆