【问题标题】:staticwebapp.config.json not working with github Azure static web site?staticwebapp.config.json 不能与 github Azure 静态网站一起使用?
【发布时间】:2021-08-26 08:41:11
【问题描述】:

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

/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 在: 推: 分支机构: - 主要的 拉取请求: 类型:[打开、同步、重新打开、关闭] 分支机构: - 主要的 工作: build_and_deploy_job: 如果:github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'close') 运行:ubuntu-latest 名称:构建和部署作业 脚步: - 使用:actions/checkout@v2 和: 子模块:真 - 名称:构建和部署 id:构建部署 用途:Azure/static-web-apps-deploy@v0.0.1-preview 和: azure_static_web_apps_api_token:${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_xxx }} repo_token: ${{ secrets.GITHUB_TOKEN }} # 用于 Github 集成(即 PR cmets) 行动:“上传” ###### 存储库/构建配置 - 这些值可以配置为符合您的应用程序要求。 ###### # 有关静态 Web 应用工作流配置的更多信息,请访问:https://aka.ms/swaworkflowconfig app_location: "/" # 应用源码路径 api_location: "api" # API 源代码路径 - 可选 output_location: "" # 构建的应用内容目录 - 可选 ###### 存储库/构建配置结束###### close_pull_request_job: 如果:github.event_name == 'pull_request' && github.event.action == '关闭' 运行:ubuntu-latest 名称:关闭拉取请求作业 脚步: - 名称:关闭拉取请求 id: closepull请求 用途:Azure/static-web-apps-deploy@v0.0.1-preview 和: azure_static_web_apps_api_token:${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_xxx }} 行动:“关闭”

json 文件如下所示:

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

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

【问题讨论】:

    标签: azure-static-web-app azure-static-website-routing


    【解决方案1】:

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

    【讨论】:

    • 很高兴您解决了这个问题。感谢您与社区分享解决方案。 - staticwebapp.config.json 的推荐位置在工作流文件中设置为 app_location 的文件夹中。但是,该文件可以放置在设置为 app_location 的文件夹内的任何子文件夹中。如果存在 staticwebapp.config.json,则忽略已弃用的 routes.json 文件。重写定义规则 - docs.microsoft.com/azure/static-web-apps/…
    猜你喜欢
    • 2020-10-18
    • 1970-01-01
    • 1970-01-01
    • 2016-08-15
    • 2020-10-02
    • 2016-05-15
    • 2019-03-10
    • 2017-10-28
    • 1970-01-01
    相关资源
    最近更新 更多