简体   繁体   English

如何使用 Visual Studio Code 中的 Azure App Service 插件将 React 部署到 Azure Web App?

[英]How to deploy React to Azure Web App using the Azure App Service plugin in Visual Studio Code?

I tried following the many existing questions and blogs online but I couldn't get it to work, I have created a simple React app with this setup:我尝试在网上关注许多现有的问题和博客,但我无法让它工作,我用这个设置创建了一个简单的 React 应用程序:

在此处输入图片说明

It run fine locally.它在本地运行良好。 I also ran "npm run build".我还运行了“npm run build”。 I also added a web.config to my public folder, which got copied to my build folder with the following content:我还在我的公共文件夹中添加了一个 web.config,它被复制到我的构建文件夹中,内容如下:

<?xml version="1.0"?>    
<configuration>    
    <system.webServer>    
        <httpErrors errorMode="Detailed"></httpErrors>
        <rewrite>    
            <rules>    
                <rule name="React Routes" stopProcessing="true">    
                    <match url=".*" />    
                    <conditions logicalGrouping="MatchAll">    
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />    
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />    
                    <add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />    
                    </conditions>    
                    <action type="Rewrite" url="/" />    
                </rule>    
            </rules>    
        </rewrite>    
    </system.webServer>    
</configuration>   

My public folder look like this:我的公用文件夹如下所示:

在此处输入图片说明

I create my Azure Web App online fine and I was able to deploy to it but I browse to it I get this error:我在线创建了我的 Azure Web 应用程序,并且能够部署到它,但是我浏览到它时出现此错误:

The page cannot be displayed because an internal server error has occurred.

What error do I have?我有什么错误?

The page cannot be displayed because an internal server error has occurred.由于发生内部服务器错误,无法显示该页面。

This error may occur if application is not deployed properly or dependencies are not loaded.如果未正确部署应用程序或未加载依赖项,则可能会发生此错误。

Steps to deploy React to Azure Web App :将 React 部署到 Azure Web App 的步骤:

  • Open your Project in VS Code在 VS Code 中打开你的项目

  • Go to Extensions.转到扩展。 Search for Azure App Service and click on Install.搜索 Azure 应用服务并单击安装。在此处输入图片说明

  • Go to Azure App Service.转到 Azure 应用服务。 Sign in to your Azure Account.登录到你的 Azure 帐户。

  • Click on Deploy to Web App.单击部署到 Web 应用程序。

  • Select your Subscription.选择您的订阅。 Select your App Service.选择您的应用服务。

  • Now you should be able to deploy your react app to Azure App Service现在您应该能够将您的 React 应用程序部署到 Azure 应用服务

在此处输入图片说明

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将React Webpack Web应用程序部署到Azure App Service? - How do I deploy a React Webpack web app to Azure App Service? 如何将React App从GitHub部署到Azure App Service - How to Deploy React App from GitHub to Azure App Service Azure App Service Deploy无法成功部署Web应用程序 - Azure App Service Deploy does not deploy web app successfully 如何将基于 browserHistory 的 React 应用程序部署到 Azure 应用服务? - How to deploy browserHistory based React applications to Azure App Service? 尝试将 React 应用程序部署到 Azure 应用程序服务时出错 - getting error while trying to deploy a React app to Azure App Service React App 部署到 Azure App Service 后失败 - React App fails after deploy to Azure App Service 无法将 React 应用(构建)文件夹部署到应用服务 Azure - Failed to deploy React app (build) folder to App Service Azure 如何在 Azure 上部署 NextJs SSR React 应用程序 - How to deploy a NextJs SSR React app on Azure 如何将 React 应用程序的生产 npm 构建部署到 Azure 应用服务 - How can I deploy production npm build of react app to Azure App Service 无法在 Azure App 服务上部署 React JS 应用程序 - Unable to deploy React JS application on Azure App service
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM