aws-amplify / amplify-hosting

AWS Amplify Hosting provides a Git-based workflow for deploying and hosting fullstack serverless web applications.
https://aws.amazon.com/amplify/hosting/
Apache License 2.0
449 stars 113 forks source link

Some gzip files are not served for blazor wasm project #2942

Open emerabet opened 1 year ago

emerabet commented 1 year ago

Before opening, please confirm:

App Id

d3drcnfa1b1cqc

Region

eu-west-1

Amplify Hosting feature

Performance

Describe the bug

Hello,

I'm trying to host a blazor wasm project using amplify connected to github. I followed this guide https://aws.amazon.com/fr/blogs/devops/deploy-net-blazor-webassembly-application-to-aws-amplify/ The gzip files and brotli files are well generated by the build command dotnet publish -c Release -o release but when deployed by Amplify only .js and .css are served with content-enconding to gzip.

1 2

Expected behavior

All gzip files should be served

Reproduction steps

  1. Create a new blazor wasm project
  2. Deploy using using amplify hosting
  3. Open the web site with the network tab active

or

Open this url with network tab active: https://main.d3drcnfa1b1cqc.amplifyapp.com

Build Settings

version: 1
applications:
  - frontend:
      phases:
        preBuild:
          commands:
            - curl -sSL https://dot.net/v1/dotnet-install.sh > dotnet-install.sh
            - chmod +x *.sh
            - ./dotnet-install.sh -c 6.0 -InstallDir ./dotnet6
            - ./dotnet6/dotnet --version
        build:
          commands:
            - ./dotnet6/dotnet publish -c Release -o release
      artifacts:
        baseDirectory: /release/wwwroot
        files:
          - '**/*'
      cache:
        paths: []

Additional information

Thanks for your help

ghost commented 1 year ago

Hi @emerabet try adding this SPA redirect rule via the console. Make sure to add the missing file extensions to the regex. https://docs.aws.amazon.com/amplify/latest/userguide/redirects.html#redirects-for-single-page-web-apps-spa

ex. </^[^.]+$|\.(?!(css|gif|ico|jpg|js|png|txt|svg|woff|woff2|ttf|map|json|webp|gz|br)$)([^.]+$)/>

ghost commented 1 year ago

Here is more specific documentation for your use case: https://swimburger.net/blog/dotnet/how-to-deploy-blazor-webassembly-to-aws-amplify#rewrite-all-requests-to-indexhtml

emerabet commented 1 year ago

Hi @hloriana I tried to add the rewrite rule you suggested but with no success. the browser keeps loading the .dll files instead of the .gz generated during the build

Capture d’écran 2022-08-26 à 09 12 39 Capture d’écran 2022-08-26 à 09 12 11

Thanks!