{"id":26462928,"url":"https://github.com/clerk/nextjs-middleware-debugging","last_synced_at":"2026-05-19T15:39:57.970Z","repository":{"id":104053934,"uuid":"537830970","full_name":"clerk/nextjs-middleware-debugging","owner":"clerk","description":null,"archived":false,"fork":false,"pushed_at":"2022-09-18T03:50:26.000Z","size":78,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2023-11-03T07:34:51.778Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"nextjs-middleware-debugging.vercel.app","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/clerk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2022-09-17T14:20:13.000Z","updated_at":"2023-11-03T07:34:53.403Z","dependencies_parsed_at":"2023-07-25T18:15:54.931Z","dependency_job_id":null,"html_url":"https://github.com/clerk/nextjs-middleware-debugging","commit_stats":null,"previous_names":["clerk/nextjs-middleware-debugging"],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clerk%2Fnextjs-middleware-debugging","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clerk%2Fnextjs-middleware-debugging/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clerk%2Fnextjs-middleware-debugging/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clerk%2Fnextjs-middleware-debugging/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/clerk","download_url":"https://codeload.github.com/clerk/nextjs-middleware-debugging/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244367601,"owners_count":20441921,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-19T06:26:17.937Z","updated_at":"2026-05-19T15:39:57.907Z","avatar_url":"https://github.com/clerk.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# About\n\nThis repo was built to help determine how calling `NextResponse.rewrite()` in Next.js middleware impacts the Request object that is received at the final _endpoint_, which can be either a React Page or a API Route.\n\nFor API routes, we investigate the value inside `request.url`\n\nFor React pages, we investigate the value inside `context.req.url`\n\nWe found that there is inconsistency across development and production, and across node and edge runtimes. We detail those inconsistencies below and provide commands to reproduce.\n\n# Using this repo\n\nThere are four \"endpoints\" inside this repo:\n\n1. /page/node\n2. /page/edge\n3. /api/node\n4. /api/edge\n\nThe endpoints run on the runtime indicated in their path, using the Next.js [switchable runtime](https://nextjs.org/docs/advanced-features/react-18/switchable-runtime).\n\nPage endpoints print the request URL inside the HTML body. It wraps the value in triple hyphens (e.g. ---) for easy parsing from the command line.\n\nAPI endpoints print the request URL _as_ the body. There is no HTML body we need to parse through, so we only print the raw value.\n\n# Results\n\nWe ran cURL requests against both development and production to determine their behavior. The production environment is hosted on Vercel.\n\n## Control\n\nTo establish a baseline, we ran the test while accessing the endpoint URLs directly. In these tests, our middleware returns `NextResponse.next()`.\n\nFor completeness, we include a query string (?foo=bar) in the URL.\n\n### Command\n\nNote: You must be running this repository on localhost:3000 before running the command\n\n```\necho \"Requesting: /page/node?foo=bar\\n\" \\\n\u0026\u0026 echo -n \"Dev context.req.url:  \" \\\n\u0026\u0026 curl -s \"http://localhost:3000/page/node?foo=bar\" | awk -F '---' '{ print $2 }' \\\n\u0026\u0026 echo -n \"Prod context.req.url: \" \\\n\u0026\u0026 curl -s \"https://nextjs-middleware-debugging.vercel.app/page/node?foo=bar\" | awk -F '---' '{ print $2 }' \\\n\u0026\u0026 echo \"\\n\\nRequesting: /page/edge?foo=bar\\n\" \\\n\u0026\u0026 echo -n \"Dev context.req.url:  \" \\\n\u0026\u0026 curl -s \"http://localhost:3000/page/edge?foo=bar\" | awk -F '---' '{ print $2 }' \\\n\u0026\u0026 echo -n \"Prod context.req.url: \" \\\n\u0026\u0026 curl -s \"https://nextjs-middleware-debugging.vercel.app/page/edge?foo=bar\" | awk -F '---' '{ print $2 }' \\\n\u0026\u0026 echo \"\\n\\nRequesting: /api/node?foo=bar\\n\" \\\n\u0026\u0026 echo -n \"Dev request.url:  \" \\\n\u0026\u0026 curl -s \"http://localhost:3000/api/node?foo=bar\" \\\n\u0026\u0026 echo -n \"\\nProd request.url: \" \\\n\u0026\u0026 curl -s \"https://nextjs-middleware-debugging.vercel.app/api/node?foo=bar\" \\\n\u0026\u0026 echo \"\\n\\n\\nRequesting: /api/edge?foo=bar\\n\" \\\n\u0026\u0026 echo -n \"Dev request.url:  \" \\\n\u0026\u0026 curl -s \"http://localhost:3000/api/edge?foo=bar\" \\\n\u0026\u0026 echo -n \"\\nProd request.url: \" \\\n\u0026\u0026 curl -s \"https://nextjs-middleware-debugging.vercel.app/api/edge?foo=bar\"\n```\n\n### Results\n\n```\nRequesting: /page/node?foo=bar\n\nDev context.req.url:  /page/node?foo=bar\nProd context.req.url: /page/node?foo=bar\n\n\nRequesting: /page/edge?foo=bar\n\nDev context.req.url:  /page/edge?foo=bar\nProd context.req.url: /page/edge?foo=bar\n\n\nRequesting: /api/node?foo=bar\n\nDev request.url:  /api/node?foo=bar\nProd request.url: /api/node?foo=bar\n\n\nRequesting: /api/edge?foo=bar\n\nDev request.url:  http://localhost:3000/api/edge?foo=bar\nProd request.url: https://nextjs-middleware-debugging.vercel.app/api/edge?foo=bar\n```\n\nWith `NextResponse.next()`, all endpoints behave consistently, with one small exception.\n\nEdge API routes return the full URL, while others are missing the origin.\n\n## Test\n\nTo test `NextResponse.rewrite()`, we request a different path (/test), and use middleware to rewrite the request to the appropriate endpoint.\n\nFor completeness, we include a query string (?foo=bar) in the rewrite URL.\n\n### Command\n\nNote: You must be running this repository on localhost:3000 before running the command\n\n```\necho \"Requesting: /test?rewrite=/page/node?foo=bar\\n\" \\\n\u0026\u0026 echo -n \"Dev context.req.url:  \" \\\n\u0026\u0026 curl -s \"http://localhost:3000/test?rewrite=/page/node?foo=bar\" | awk -F '---' '{ print $2 }' \\\n\u0026\u0026 echo -n \"Prod context.req.url: \" \\\n\u0026\u0026 curl -s \"https://nextjs-middleware-debugging.vercel.app/test?rewrite=/page/node?foo=bar\" | awk -F '---' '{ print $2 }' \\\n\u0026\u0026 echo \"\\n\\nRequesting: /test?rewrite=/page/edge?foo=bar\\n\" \\\n\u0026\u0026 echo -n \"Dev context.req.url:  \" \\\n\u0026\u0026 curl -s \"http://localhost:3000/test?rewrite=/page/edge?foo=bar\" | awk -F '---' '{ print $2 }' \\\n\u0026\u0026 echo -n \"Prod context.req.url: \" \\\n\u0026\u0026 curl -s \"https://nextjs-middleware-debugging.vercel.app/test?rewrite=/page/edge?foo=bar\" | awk -F '---' '{ print $2 }' \\\n\u0026\u0026 echo \"\\n\\nRequesting: /test?rewrite=/api/node?foo=bar\\n\" \\\n\u0026\u0026 echo -n \"Dev request.url:  \" \\\n\u0026\u0026 curl -s \"http://localhost:3000/test?rewrite=/api/node?foo=bar\" \\\n\u0026\u0026 echo -n \"\\nProd request.url: \" \\\n\u0026\u0026 curl -s \"https://nextjs-middleware-debugging.vercel.app/test?rewrite=/api/node?foo=bar\" \\\n\u0026\u0026 echo \"\\n\\n\\nRequesting: /test?rewrite=/api/edge?foo=bar\\n\" \\\n\u0026\u0026 echo -n \"Dev request.url:  \" \\\n\u0026\u0026 curl -s \"http://localhost:3000/test?rewrite=/api/edge?foo=bar\" \\\n\u0026\u0026 echo -n \"\\nProd request.url: \" \\\n\u0026\u0026 curl -s \"https://nextjs-middleware-debugging.vercel.app/test?rewrite=/api/edge?foo=bar\"\n```\n\n### Results\n\n```\nRequesting: /test?rewrite=/page/node?foo=bar\n\nDev context.req.url:  /test?rewrite=/page/node?foo=bar\nProd context.req.url: /test?foo=bar\n\n\nRequesting: /test?rewrite=/page/edge?foo=bar\n\nDev context.req.url:  /page/edge?foo=bar\nProd context.req.url: /test?foo=bar\n\n\nRequesting: /test?rewrite=/api/node?foo=bar\n\nDev request.url:  /test?rewrite=/api/node?foo=bar\nProd request.url: /test?foo=bar\n\n\nRequesting: /test?rewrite=/api/edge?foo=bar\n\nDev request.url:  http://localhost:3000/api/edge?foo=bar\nProd request.url: https://nextjs-middleware-debugging.vercel.app/test?foo=bar\n```\n\nThough we expected every scenario to show the rewritten request URL, that was only the case in 2 of 8 scenarios.\n\nThe results show inconsistency across both (edge vs node) and (dev vs prod) when a rewrite is applied.\n\n**/page/node**\n\n❌ In dev, `context.req.url` reflects the complete original request URL\n\n❌ In prod, `context.req.url` reflects the original pathname and the rewritten query string\n\n**/page/edge**\n\n✅ In dev, `context.req.url` reflects the complete rewritten request URL\n\n❌ In prod, `context.req.url` reflects the original pathname and the rewritten query string\n\n**/api/node**\n\n❌ In dev, `request.url` reflects the complete original request URL\n\n❌ In prod, `request.url` reflects the original pathname and the rewritten query string\n\n**/api/edge**\n\n✅ In dev, `request.url` reflects the complete rewritten request URL\n\n❌ In prod, `request.url` reflects the original pathname and the rewritten query string\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclerk%2Fnextjs-middleware-debugging","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclerk%2Fnextjs-middleware-debugging","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclerk%2Fnextjs-middleware-debugging/lists"}