Skip to content

Commit 6ea4e43

Browse files
committed
Reverse execution order of Pages Functions middlewares
1 parent 4a27f04 commit 6ea4e43

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

.changeset/fuzzy-ads-rush.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
Reverse execution order of Pages Functions middlewares

packages/wrangler/pages/functions/template-worker.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ type WorkerContext = {
4545
function* executeRequest(request: Request, env: Env) {
4646
const requestPath = new URL(request.url).pathname;
4747

48-
// First, iterate through the routes and execute "middlewares" on partial route matches
49-
for (const route of routes) {
48+
// First, iterate through the routes (backwards) and execute "middlewares" on partial route matches
49+
for (const route of [...routes].reverse()) {
5050
if (
5151
route.methods.length &&
5252
!route.methods.includes(request.method as HTTPMethod)

0 commit comments

Comments
 (0)