简体   繁体   English

同一 Azure 存储帐户上的多个 React 站点

[英]Multiple React sites on the same Azure storage account

There is a need to improve our CI/CD process for our React application.需要改进我们的 React 应用程序的 CI/CD 流程。 The bottom line is:底线是:

  • any commit to any git branch except release branches and master should trigger build/deploy process to Azure storage account that is currently configures as Static site and linked with CDN endpoint (Microsoft Standard).对除发布分支和主分支以外的任何 git 分支的任何提交都应触发对当前配置为静态站点并与 CDN 端点(Microsoft 标准)链接的 Azure 存储帐户的构建/部署过程。
  • the deployment destination should be {rootUrl}/{branchName}部署目的地应该是{rootUrl}/{branchName}

So we want to have multiple React applications on the same storage account/CDN endpoint.所以我们希望在同一个存储帐户/CDN 端点上有多个 React 应用程序。 This would allow our QA team to test features independently.这将允许我们的 QA 团队独立测试功能。

I already made the following changes in the app that allows the app to work using relative path on localhost:我已经在应用程序中进行了以下更改,允许应用程序使用本地主机上的相对路径工作:

  1. set homepage property in package.json在 package.json 中设置主页属性
"homepage": "http://localhost:3001/testApp"
  1. set basename attribute of Router设置路由器的basename属性
  <Router basename={process.env.RELATIVE_ROOT_URL} {...props}>
...

3). 3)。 add a line to the .env file:在 .env 文件中添加一行:

RELATIVE_ROOT_URL=/testApp

But I don't have any idea how to change URL rewrite rule for CDN endpoint to allow to open URLs like {rootUrl}/{branchName}/somepath/ directly.但我不知道如何更改 CDN 端点的 URL 重写规则以允许直接打开像{rootUrl}/{branchName}/somepath/这样的 URL。

PS Currently we have the following rule that works well for a single site per CDN endpoint: PS 目前我们有以下规则适用于每个 CDN 端点的单个站点:

Condition :条件

  • If URL file extension如果 URL 文件扩展名
  • Operator : Not greater than运算符: 不大于
  • Extension : 0分机:0
  • Case transform : No案例转换:否

Action :行动

  • Then URL rewrite然后URL重写
  • Source pattern : /源模式:/
  • Destination : /index.html目的地:/index.html
  • Preserve unmatched path : No保留不匹配的路径:否

Try the following:请尝试以下操作:

  1. Add "homepage": ".", to your package.json as it is mentioned here ."homepage": ".",到您的 package.json 中,因为它是在这里提到的。
  2. Change Router to HashRouter and remove the basename attribute.Router更改为HashRouter并删除basename属性。

Here is my example from this repo .是我来自这个repo 的例子。
I deploy using the following command:我使用以下命令进行部署:

az storage blob upload-batch \
  --account-name $(AZURE_STORAGE_ACCOUNT) \
  --account-key $(AZURE_STORAGE_KEY) \
  -s ./build/. \
  -d '$web/product/book-shelves'

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM