[英]Deploying on azure with create-react-app
我正在使用create-react-app開發我的React應用程序。 現在,我想將捆綁包發布到雲上。 所以我做了:
npm run build
它創建了一個build
文件夾,在其中我初始化了一個倉庫:
git init
然后添加原點
git remote add origin https://mysiteonazure.com/app.git
最終提交並推送了文件。 這樣我就可以查看我的應用程序。 當我想使用URL導航時出現了問題,因此轉到:
http://mysiteonazure.com/login
不工作。
因此,我來到了以下文章: 在Microsoft Azure上部署create-react-app
所以我的構建有:
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
: http://mypage.azurewebsite.net
我得到了:
由於發生內部服務器錯誤,因此無法顯示該頁面。
我怎么解決這個問題? 或者,如何正確發布我的應用程序?
有了詳細的信息,問題就出在引號上,我從給定的源復制了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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.