staticwebapp.config.json 无法与 github Azure 静态网站一起使用?

问题描述 投票:0回答:3

我创建了一个具有以下文件结构的简单网站:

/index.html /down.html /.github/workflows/azure-static-web-apps-xxxx.yml /staticwebapp.config.json

此部署后,我可以看到我的索引和下页,如果我修改其中任何一个,它就会神奇地出现在网站上。

问题是它忽略了 staticwebapp.config.json

我不知道该把它放在哪里,但我猜它的根源。它不起作用。大概它没有被读取或处理。

yaml 文件如下所示。我不知道它从哪里来,也不知道我是否需要它,因为该网站将是纯 HTML(非库、js 或框架):

名称:Azure 静态 Web 应用 CI/CD

在:
  推:
    分支机构:
      - 主要的
  拉请求:
    类型:[打开、同步、重新打开、关闭]
    分支机构:
      - 主要的

工作:
  构建和部署作业:
    if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != '关闭')
    运行:ubuntu-latest
    名称:构建和部署作业
    脚步:
      - 使用:actions/checkout@v2
        和:
          子模块:true
      - 名称:构建和部署
        id: 构建部署
        使用:Azure/[电子邮件受保护]
        和:
          azure_static_web_apps_api_token:${{secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_xxx }}
          repo_token: ${{ Secrets.GITHUB_TOKEN }} # 用于 Github 集成(即 PR 评论)
          动作:“上传”
          ###### 存储库/构建配置 - 可以配置这些值以满足您的应用程序要求。 ######
          # 有关静态 Web 应用程序工作流配置的更多信息,请访问:https://aka.ms/swaworkflowconfig
          app_location: "/" # 应用源代码路径
          api_location: "api" # Api源代码路径 - 可选
          output_location: "" # 构建的应用程序内容目录 - 可选
          ###### 存储库/构建配置结束 ######

  关闭拉请求作业:
    if: github.event_name == 'pull_request' && github.event.action == '关闭'
    运行:ubuntu-latest
    名称:关闭拉取请求作业
    脚步:
      - 名称:关闭拉取请求
        id: 关闭拉请求
        使用:Azure/[电子邮件受保护]
        和:
          azure_static_web_apps_api_token:${{secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_xxx }}
          动作:“关闭”

json 文件如下所示:


{
  “路线”:[
     {
     "路线": "/index.html",
     "重写": "/down.html",
     “状态代码”:307
    },
    {
     “路线”:“/测试/”,
     "重写": "/down.html",
    }
    
    ]
}

/test/ 给出 404,/index.html 给出 /index.html,即所有路由都不起作用。

azure-static-web-app azure-static-website-routing
3个回答
5
投票

好的,解决方案非常简单。在 Azure 门户中,如果您转到静态 Web 应用程序概述页面,右上角有一个指向“部署历史记录”的链接。然后您可以看到上面的代码失败了,因为它不允许重写 statusCode。删除了这个,现在它按预期工作了。


1
投票

您可以尝试像这样提供您的配置文件路径

steps:
- task: AzureStaticWebApp@0
  displayName: 'Static Web App: '
  inputs:
    app_location: /build
    config_file_location: ./
    azure_static_web_apps_api_token: '$(DEPLOY_TOKEN)'

0
投票

就我而言,这是因为我使用免费计划尝试配置 IP 地址白名单。组网配置需要标准方案:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.