6

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.

3 Answers 3

7

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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 - learn.microsoft.com/azure/static-web-apps/…
2

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

3 Comments

is there any documentation regarding config_file_location? It isn't mentioned in learn.microsoft.com/en-us/azure/static-web-apps/…
really pqnet has right
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: github.com/Azure/static-web-apps-deploy/blob/v1/…
1

In my case it was because I was on the Free plan trying to configure an IP address whitelist. A standard plan is required for networking configuration:

enter image description here

1 Comment

Not sure how the community rates this stuff but I gave you a plus one for adding a related problem and answer to this question to make it a bit easier for searchers to perhaps bumble into it a bit of knowledge.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.