From b140a3f6d821127f927b7cb938294549e41c5168 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Fri, 22 Nov 2024 10:26:48 +0000 Subject: [PATCH] fix(routing): don't access Request headers (#12498) Co-authored-by: ascorbic <213306+ascorbic@users.noreply.github.com> --- .changeset/unlucky-kids-compete.md | 5 +++++ packages/astro/src/core/middleware/noop-middleware.ts | 7 ++++--- 2 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 .changeset/unlucky-kids-compete.md diff --git a/.changeset/unlucky-kids-compete.md b/.changeset/unlucky-kids-compete.md new file mode 100644 index 000000000000..e4b59791ea21 --- /dev/null +++ b/.changeset/unlucky-kids-compete.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fixes a regression where Astro was trying to access `Request.headers` diff --git a/packages/astro/src/core/middleware/noop-middleware.ts b/packages/astro/src/core/middleware/noop-middleware.ts index b141285f699c..c0c9648330d0 100644 --- a/packages/astro/src/core/middleware/noop-middleware.ts +++ b/packages/astro/src/core/middleware/noop-middleware.ts @@ -1,7 +1,8 @@ import type { MiddlewareHandler } from '../../@types/astro.js'; import { NOOP_MIDDLEWARE_HEADER } from '../constants.js'; -export const NOOP_MIDDLEWARE_FN: MiddlewareHandler = (ctx, next) => { - ctx.request.headers.set(NOOP_MIDDLEWARE_HEADER, 'true'); - return next(); +export const NOOP_MIDDLEWARE_FN: MiddlewareHandler = async (_ctx, next) => { + const response = await next(); + response.headers.set(NOOP_MIDDLEWARE_HEADER, 'true'); + return response; };