withastro / adapters

Home for Astro's core maintained adapters
46 stars 25 forks source link

Astro middleware breaks Content-Encoding on netlify #269

Open docapi opened 1 month ago

docapi commented 1 month ago

Astro Info

Astro                    v4.8.5
Node                     v20.11.0
System                   macOS (arm64)
Package Manager          npm
Output                   server
Adapter                  netlify
Integrations             astro-robots-txt
                         @astrojs/alpinejs
                         astro-compress

Describe the Bug

Netlify normally compresses pages with Brotli ("Content-Encoding : br"). If middleware (middleware.ts) is used, e.g. to set security headers, compression no longer works. Example for middleware.ts:

import { defineMiddleware } from "astro/middleware";

export const onRequest = defineMiddleware(async (context, next) => {
  const response = await next();

  response.headers.set("Referrer-Policy", "same-origin");

  return response;
});

What's the expected result?

Netlify continues to compress the pages

Link to Minimal Reproducible Example

This problem happen specifically on netlify so I cannot reproduce on stackblitz or others

Participation