git - 使用 create-react-app 在 azure 上部署

标签 git azure reactjs react-router

我正在使用 create-react-app 来开发我的 React 应用程序。现在我想在云上发布 bundle 。所以我这样做了:

npm run build

它创建了一个 build 文件夹,我在其中初始化了一个存储库:

git init

然后添加原点

git remote add origin https://mysiteonazure.com/app.git

终于提交并推送了文件。所以我能够查看我的应用程序。当我想使用 URL 进行导航时,问题出现了,因此转向:

http://mysiteonazure.com/login

没用。

所以我来到了下面这篇文章Deploying create-react-app on Microsoft Azure

所以我的构建有:

build-azure
|_.git
|_static
|_asset-manifest-json
|_favicon.ico
|_index.html

现在我添加了web.config

build-azure
|_.git
|_static
|_asset-manifest-json
|_favicon.ico
|_index.html
|_web.config

与:

<?xml version=”1.0"?>
<configuration>
 <system.webServer>
 <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>

但是现在当我进入主页:http://mypage.azurewebsite.net 我得到:

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

如何解决这个问题?或者,如何正确发布我的应用程序?

最佳答案

鉴于详细信息,问题在于引号,我从给定源复制了 web.config,它还有其他引号,所以真正的 web.config > 是:

<?xml version="1.0"?>
<configuration>
 <system.webServer>
 <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>

关于git - 使用 create-react-app 在 azure 上部署,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41983026/

相关文章:

linux - Open vSwitch 无法在 Docker 上运行

svn - git-svn 显示 svn 仓库 url

git - git 过滤器分支和 git 子树之间的区别?

azure - 如何修复 Azure Cloud Shell 错误 "MissingSubscriptionRegistration - The subscription is not registered to use namespace ' Microsoft.Storage'"

javascript - React 如何连接 JS 文件和 HTML 文件

javascript - 如何使 FontAwesomeIcon react 在鼠标悬停时不改变颜色

javascript - Redux + react + FireBase : how to use a state when updating

git - 在 Heroku 上创建 Node.js 应用程序时,我应该将文件夹 "node_modules" checkin Git 吗?

azure - 以编程方式创建 Azure KeyVault secret 时,如何修复“"Operation ' set' not allowed”错误?

服务主体的 Azure Databricks Git 凭据