staticwebapp.config.json not working with github Azure static web site?

11.7k views Asked by At

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/[email protected]
        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/[email protected]
        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.

2

There are 2 answers

1
John Little On BEST ANSWER

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.

3
Speedyankur On

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)'