Repository navigation
refactor: rename middleware.ts to proxy.ts - #812
Conversation
Bumps next 16.0.10 -> 16.3.0 and react/react-dom 19.2.1 -> 19.2.8. 16.3 brings Turbopack disk caching for `next build`, memory eviction in dev, and native Node.js streams in the App Router render path. Also drops `eslint-config-next` (15.1.7). It is a dead dependency here: `eslint.config.js` builds its own flat config from @typescript-eslint, prettier, jsdoc and import, and never references the Next config or @next/eslint-plugin-next. Nothing but package.json mentioned it. Commits the `<!-- BEGIN:nextjs-agent-rules -->` block that `next dev` writes into AGENTS.md on 16.2+. It points agents at version-matched docs in node_modules/next/dist/docs/, and `next dev` re-adds it on every run, so committing it is what keeps the tree clean. Tracked in recoupable/app#1929.
Next 16.3 switched the default type checker to the project-local `tsc` CLI. Per the useTypeScriptCli docs it checks "the complete project selected by the configured tsconfig file ... including test files", where 16.0's compiler-API checker narrowed the set to app code. tsconfig.json is `"include": ["**/*.ts"]`, so every __tests__ file entered the build's type check for the first time and 203 pre-existing fixture errors failed the build and the preview deploy. They are not regressions: on main with 16.0.10 reinstalled and a cold tsbuildinfo, `next build` emits 0 error TS lines, and this bump introduces 0 new errors while fixing 33 of them. Points the build at a tsconfig.build.json that excludes test files, so the build checks what it checked before. This is scoping, not silencing -- `pnpm exec tsc --noEmit` still uses the root tsconfig and still reports all 203, which is where the burn-down will happen. Verified: build compiles and type-checks with 0 errors, then stops at `STRIPE_SK environment variable is required` collecting page data, which is the same point main reaches locally. tsc --noEmit still reports 203. Tests 797/797 files, 4329/4329.
Next 16 deprecated the `middleware` file convention in favour of `proxy`,
and `next dev` said so on every boot:
⚠ The "middleware" file convention is deprecated.
Please use "proxy" instead.
Renames the file and the exported binding. x402-next is unaffected:
paymentMiddleware returns a plain
`(request: NextRequest) => Promise<NextResponse>`, and nothing in the
package keys off the file name or the export name -- `export const
middleware = ...` is only the Next convention in their docs. No file in
this repo imported it either.
Also drops `runtime: "nodejs"` from the config export. Next rejects the
file outright with it present:
⨯ Route segment config is not allowed in Proxy file at "./proxy.ts".
Proxy always runs on Node.js runtime.
Proxy is Node-only and not configurable, which is what we already wanted,
so this is a deletion rather than a behaviour change. `matcher` stays.
Verified locally on `next dev`: deprecation warning gone, no route-segment
error, `proxy.ts: 415ms` in the request log confirming it runs, and an
unpaid GET /api/x402/image/generate still returns the 402 challenge with
maxAmountRequired 150000. Build type check 0 errors, lint 0 errors, tests
797/797 files and 4329/4329.
Sequenced last in the fleet because it is the only change touching a live
payment path.
Tracked in recoupable/app#1929.
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedReview was skipped due to path filters ⛔ Files ignored due to path filters (1)
CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Preview verification: ✅ green — paid path confirmed unchangedThis is the check I flagged as still pending in the PR body. Preview for The x402 paid path
The proxy still gates everything else
The No secret or env value appears in any response. All 8 PRs in recoupable/app#1929 are now open and verified. |
There was a problem hiding this comment.
1 issue found across 1 file
Confidence score: 4/5
- In
proxy.ts, the rename appears incomplete in checked-in setup/docs, so contributors may follow stale guidance and recreate a deprecatedmiddleware.tsentrypoint, causing misconfigured Next.js 16 behavior and avoidable onboarding friction — update all setup instructions/templates to reference the proxy convention only.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="proxy.ts">
<violation number="1" location="proxy.ts:55">
P2: The rename leaves checked-in setup and contributor guidance pointing at the removed `middleware.ts` convention, so users following it will recreate the deprecated entrypoint instead of the Next.js 16 proxy and retain the invalid runtime config; update those examples and guidance to `proxy.ts`/`proxy` with matcher-only config.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| }; | ||
|
|
||
| export const middleware = paymentMiddleware( | ||
| export const proxy = paymentMiddleware( |
There was a problem hiding this comment.
P2: The rename leaves checked-in setup and contributor guidance pointing at the removed middleware.ts convention, so users following it will recreate the deprecated entrypoint instead of the Next.js 16 proxy and retain the invalid runtime config; update those examples and guidance to proxy.ts/proxy with matcher-only config.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At proxy.ts, line 55:
<comment>The rename leaves checked-in setup and contributor guidance pointing at the removed `middleware.ts` convention, so users following it will recreate the deprecated entrypoint instead of the Next.js 16 proxy and retain the invalid runtime config; update those examples and guidance to `proxy.ts`/`proxy` with matcher-only config.</comment>
<file context>
@@ -52,7 +52,7 @@ const imageGenerateOutputSchema = {
};
-export const middleware = paymentMiddleware(
+export const proxy = paymentMiddleware(
SMART_ACCOUNT_ADDRESS,
{
</file context>
Preview verification (re-run on current head): ✅ greenRe-verified after retargeting to Preview: https://api-gki32b1h4-recoup.vercel.app Production still runs The 402 payment challenge — field by field vs productionThis is the whole risk of the PR, so I compared the full challenge rather than just the status code:
Every field matches, including the full The proxy still gates everything it did as middleware
A prod key 401s against previews (different hash salt), so the key was minted on the preview itself via the unauthenticated agent-signup route. Notes
This is the last PR in the recoupable/app#1929 fleet. |
Part of recoupable/app#1929 (PR 8 of 8, the last one).
Why
Next 16 deprecated the
middlewareconvention in favour ofproxy, andnext devsaid so on every boot:What changed
1. Renamed the file and the exported binding (
export const middleware→export const proxy).Checked the coupling before trusting it:
x402-next@0.7.3'spaymentMiddlewarereturns a plain(request: NextRequest) => Promise<NextResponse>and nothing in the package keys off the file name or the export name —export const middleware = ...is just the Next convention as written in their docs. No file in this repo imported it either.2. Dropped
runtime: "nodejs"from the config export. This one only showed up by running it. Next rejects the file outright when it is present:Proxy is Node-only and not configurable, which is exactly what the old
runtime: "nodejs"was asking for — so this is a deletion, not a behaviour change.matcheris untouched.Verification
Locally on
next dev:middlewaredeprecation warningruntimeGET /api/artists 500 in 11.9s (… proxy.ts: 415ms …)— the request log names itGET /api/x402/image/generate402{"x402Version":1,"error":"X-PAYMENT header is required","accepts":[{"scheme":"exact","network":"base","maxAmountRequired":"150000",…}]}pnpm buildtype checkpnpm lint:checkpnpm testThe
500on/api/artistsis that route throwingSTRIPE_SK environment variable is requiredin my shell — application code, reached through the proxy, which is the point.The
402payload matches the baseline captured on #811's preview before this rename: same price (150000= $0.15 at USDC's 6 decimals), same network, same description. The paid path is byte-for-byte unchanged.Before merging
I'd want the same 402 check re-run against this branch's own preview deployment, not just locally — the facilitator and
SMART_ACCOUNT_ADDRESSdiffer by environment. Happy to run it once the preview is up; flagging rather than claiming it.🤖 Generated with Claude Code
Summary by cubic
Renamed Next.js middleware to proxy to align with
next@16and removed the deprecated runtime config. Fixes the dev warning and keeps the x402 payment challenge unchanged.middleware.tstoproxy.tsand changed export frommiddlewaretoproxy.runtime: "nodejs"from config;matcherunchanged.GET /api/x402/image/generatereturns the same 402; build, lint, and tests pass.Written for commit b2da474. Summary will update on new commits.