From d3caf912f6cda9c8ef8423345ab0a2746ea1af4b Mon Sep 17 00:00:00 2001 From: strofimo Date: Mon, 24 Jun 2024 18:45:21 +0100 Subject: [PATCH] Middleware move permanently fix (#810) --- .changeset/hot-socks-beg.md | 5 +++++ .../next-on-pages/templates/_worker.js/routes-matcher.ts | 6 ++++++ 2 files changed, 11 insertions(+) create mode 100644 .changeset/hot-socks-beg.md diff --git a/.changeset/hot-socks-beg.md b/.changeset/hot-socks-beg.md new file mode 100644 index 000000000..77050c885 --- /dev/null +++ b/.changeset/hot-socks-beg.md @@ -0,0 +1,5 @@ +--- +'@cloudflare/next-on-pages': patch +--- + +Middleware move permanently fix diff --git a/packages/next-on-pages/templates/_worker.js/routes-matcher.ts b/packages/next-on-pages/templates/_worker.js/routes-matcher.ts index c00b22b7a..6e7f04044 100644 --- a/packages/next-on-pages/templates/_worker.js/routes-matcher.ts +++ b/packages/next-on-pages/templates/_worker.js/routes-matcher.ts @@ -215,6 +215,12 @@ export class RoutesMatcher { // to continue and did not rewrite/redirect the URL. this.body = resp.body; this.status = resp.status; + } else if ( + resp.headers.has('location') && + resp.status >= 300 && + resp.status < 400 + ) { + this.status = resp.status; } applyHeaders(this.headers.normal, resp.headers);