Azure / static-web-apps

Azure Static Web Apps. For bugs and feature requests, please create an issue in this repo. For community discussions, latest updates, kindly refer to the Discussions Tab. To know what's new in Static Web Apps, visit https://aka.ms/swa/ThisMonth
https://aka.ms/swa
MIT License
324 stars 56 forks source link

Azure/static-web-apps-deploy@v1 deployment generates staticwebapp.config.json for Nuxt 3 #1305

Open Blaxzter opened 10 months ago

Blaxzter commented 10 months ago

I have a Nuxt3 app that generates a bunch of routes for a static site. When I run the autogenerated GitHub workflow file that uses the Azure/static-web-apps-deploy@v1 action I see all the successful Oryx generate logs only to see at the end:

  ├─ .output/server/functions/chunks/rollup/_virtual_head-static.mjs.map (111 B) (112 B gzip)
  ├─ .output/server/functions/index.mjs (405 B) (244 B gzip)
  └─ .output/server/functions/package.json (1.56 kB) (595 B gzip)
Σ Total size: 4.58 MB (1.09 MB gzip)
[success] [nitro] You can preview this build using `npx @azure/static-web-apps-cli start .output/public --api-location .output/server`
Done in 341.00s.
Preparing output...

Copying files to destination directory '/bin/staticsites/c8049899-b37e-47ef-922f-5726520e1736-swa-oryx/app'...
Done in 19 sec(s).

Removing existing manifest file
Creating a manifest file...
Manifest file created.
Copying .ostype to manifest output directory.

Done in 424 sec(s).

---End of Oryx build logs---
Try to validate location at: '/bin/staticsites/c8049899-b37e-47ef-922f-5726520e1736-swa-oryx/app/.output/public'.
Finished building app with Oryx
Using 'staticwebapp.config.json' file for configuration information, 'routes.json' will be ignored.
Encountered an issue while validating staticwebapp.config.json: The file size exceeds the limit of 20 KB.

For further information, please visit the Azure Static Web Apps documentation at https://docs.microsoft.com/en-us/azure/static-web-apps/
If you believe this behavior is unexpected, please raise a GitHub issue at https://github.com/azure/static-web-apps/issues/
Exiting

To note: Encountered an issue while validating staticwebapp.config.json: The file size exceeds the limit of 20 KB

The staticwebapp.config.json that is present in the app_location (which is /) is 464 Bytes and looks like this:

{
    "routes": [
    ],

    "navigationFallback": {
      "rewrite": "/index.html",
    },

    "responseOverrides": {
      "404": {
        "rewrite": "/index.html",
        "statusCode": 200
      }
    },

    "globalHeaders": {
      "Referrer-Policy": "strict-origin-when-cross-origin",
      "Strict-Transport-Security": "max-age=31536000; includeSubDomains",
      "X-Content-Type-Options": "nosniff",
      "X-Frame-Options": "SAMEORIGIN"    
    }
}

I tried the Oryx build locally, but that doesn't generate a staticwebapp.config.json, and I don't find any documentation that it would generate one. So I don't understand why it tells me I have a config file bigger than 20kb when it is just 464 Bytes.

To Reproduce No clue

workflow yaml file:

name: Azure Static Web Apps CI/CD

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

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@v3
        with:
          submodules: true
          lfs: false

      - name: Build And Deploy
        id: builddeploy
        uses: Azure/static-web-apps-deploy@v1
        with:
          azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_VICTORIOUS_SMOKE_0925AC503 }}
          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 your 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: ".output/server" # Api source code path - optional
          output_location: ".output/public" # 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@v1
        with:
          azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_VICTORIOUS_SMOKE_0925AC503 }}
          action: "close"

Repo is sadly not public.

Expected behavior A running static web app and a reasonable error message.

Device info (if applicable): I've run the runner on a self-hosted runner and the GitHub runner. I thought I'd be able to check the staticwebapp.config.json in the self-hosted runner, but the docker container was deleted too fast for me to search for it and copy it out. The _work directory that was set in the runner config does only contain the one staticwebapp.config.json that i provided.

Additional context We had the application successfully deployed to Vercel and AWS amplify.

thomasgauvin commented 10 months ago

The Nuxt adapter builds a specific bundle for the static assets and the serverless Azure Functions, based on the knowledge that it is building for Azure Static Web Apps. This is documented in Nitro, Nuxt's builder https://nitro.unjs.io/deploy/providers/azure#azure-static-web-apps. You could follow those docs to build locally and get the configuration file from that.

The limitation you are encountering is specific to to Static Web Apps' size restrictions: https://learn.microsoft.com/en-us/azure/static-web-apps/configuration#restrictions As you can see, the 20KB is the max file size of the configuration file.

To resolve this problem, you'd have to either reduce the generated routes that require specific configuration (ie handle more of these dynamically server-side) or use another service than Azure Static Web Apps

Blaxzter commented 10 months ago

When i run the npx @azure/static-web-apps-cli start .output/public command, I get this output:

Welcome to Azure Static Web Apps CLI (1.1.4)

***********************************************************************
* WARNING: This emulator may not match the cloud environment exactly. *
* Always deploy and test your app in Azure.                           *
***********************************************************************

[swa] 
[swa] Using workflow file:
[swa]   U:\Programming\project\.github\workflows\azure-static-web-apps-victorious-smoke-0925ac503.yml
[swa] 
[swa] Found configuration file:
[swa]   U:\Programming\project\staticwebapp.config.json
[swa]
[swa]
[swa] Serving static content:
[swa]   U:\Programming\project\.output\public
[swa]
[swa] Azure Static Web Apps emulator started at http://localhost:4280. Press CTRL+C to exit.
[swa]
[swa]

And everything works as intended with refreshes and everything. The staticwebapp.config.json is the same as mentioned above.

So why can't the deployment process not generate a new staticwebapp.config.json when i provide one?