5

I created a simple site with the following file structure:

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

This deploys, and I can see my index and down pages, and if I modify either, it magically appears on the site.

The problem is its ignoring staticwebapp.config.json

I dont know where to put it, but i am guessing the root. Its not working. Presumably its not being read or processed.

The yaml file looks like this. I don't know where this came from, or if I need it, as the site will be pure HTML (non libraires, js or frameworks):

name: Azure Static Web Apps CI/CD

on:
  push:
    branches:
      - main
  pull_request:
    types: [opened, synchronize, reopened, closed]
    branches:
      - main

jobs:
  build_and_deploy_job:
    if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed')
    runs-on: ubuntu-latest
    name: Build and Deploy Job
    steps:
      - uses: actions/checkout@v2
        with:
          submodules: true
      - name: Build And Deploy
        id: builddeploy
        uses: Azure/static-web-apps-deploy@v0.0.1-preview
        with:
          azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_xxx }}
          repo_token: ${{ secrets.GITHUB_TOKEN }} # Used for Github integrations (i.e. PR comments)
          action: "upload"
          ###### Repository/Build Configurations - These values can be configured to match you app requirements. ######
          # For more information regarding Static Web App workflow configurations, please visit: https://aka.ms/swaworkflowconfig
          app_location: "/" # App source code path
          api_location: "api" # Api source code path - optional
          output_location: "" # Built app content directory - optional
          ###### End of Repository/Build Configurations ######

  close_pull_request_job:
    if: github.event_name == 'pull_request' && github.event.action == 'closed'
    runs-on: ubuntu-latest
    name: Close Pull Request Job
    steps:
      - name: Close Pull Request
        id: closepullrequest
        uses: Azure/static-web-apps-deploy@v0.0.1-preview
        with:
          azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_xxx }}
          action: "close"

The json files looks like this:


{
  "routes": [
     {
     "route": "/index.html",
     "rewrite": "/down.html",
     "statusCode": 307
    },
    {
     "route": "/test/",
     "rewrite": "/down.html",
    }
    
    ]
}

/test/ gives 404, and /index.html gives /index.html, i.e. none of the routing is working.

John Little
  • 10,707
  • 19
  • 86
  • 158

2 Answers2

4

OK, solution was really simple. In Azure portal, if you go to the static webapp overview page, in the top right there is a link to "deployment history". Then you can see that the above was failing, as it doesn't allow statusCode with a rewrite. Removed this and now its working as expected.

John Little
  • 10,707
  • 19
  • 86
  • 158
  • 1
    Glad you figured out the issue. Thanks for sharing the solution with the community. -The recommended location for the staticwebapp.config.json is in the folder set as the app_location in the workflow file. However, the file may be placed in any subfolder within the folder set as the app_location. The deprecated routes.json file is ignored if a staticwebapp.config.json exists. rewrite defining rules - https://learn.microsoft.com/azure/static-web-apps/configuration#defining-routes – AjayKumar Aug 31 '21 at 20:43
1

You can try providing your config file path like this

steps:
- task: AzureStaticWebApp@0
  displayName: 'Static Web App: '
  inputs:
    app_location: /build
    config_file_location: ./
    azure_static_web_apps_api_token: '$(DEPLOY_TOKEN)'
Speedyankur
  • 152
  • 6
  • is there any documentation regarding `config_file_location`? It isn't mentioned in https://learn.microsoft.com/en-us/azure/static-web-apps/build-configuration – pqnet Jan 17 '23 at 13:52
  • really pqnet has right – Lluthus Jan 27 '23 at 22:25
  • It's one of those things where currently MS lacks any formal documentation, however it is a valid input and documented in the code for the action itself: https://github.com/Azure/static-web-apps-deploy/blob/v1/action.yml#L40-L41 – jwhazel Aug 14 '23 at 15:41