Skip to content

Commit

Permalink
Reverse execution order of Pages Functions middlewares
Browse files Browse the repository at this point in the history
  • Loading branch information
GregBrimble committed Jan 7, 2022
1 parent 0bf04bd commit ee4d6be
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/fuzzy-ads-rush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

Reverse execution order of Pages Functions middlewares
4 changes: 2 additions & 2 deletions packages/wrangler/pages/functions/template-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ type WorkerContext = {
function* executeRequest(request: Request, env: Env) {
const requestPath = new URL(request.url).pathname;

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

0 comments on commit ee4d6be

Please sign in to comment.