refactor: rename `middleware.ts` to `proxy.ts`
Part of recoupable/chat#1929 (PR 8 of 8, the last one).
Stacked on #811. Retarget to main once that merges.
⚠️ This is the only PR in the fleet that touches a live payment path. Sequenced last deliberately. Verification below focuses on proving the x402 challenge is unchanged.
Why
Next 16 deprecated the middleware convention in favour of proxy, and next dev said so on every boot:
⚠ The "middleware" file convention is deprecated. Please use "proxy" instead.
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's 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 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:
⨯ 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 exactly what the old runtime: "nodejs" was asking for — so this is a deletion, not a behaviour change. matcher is untouched.
Verification
Locally on next dev:
| Check | Result |
|---|---|
middleware deprecation warning | ✅ gone |
| Route-segment-config error | ✅ gone after dropping runtime |
| Proxy actually executing | ✅ GET /api/artists 500 in 11.9s (… proxy.ts: 415ms …) — the request log names it |
Unpaid GET /api/x402/image/generate | ✅ 402 {"x402Version":1,"error":"X-PAYMENT header is required","accepts":[{"scheme":"exact","network":"base","maxAmountRequired":"150000",…}]} |
pnpm build type check | ✅ 0 errors |
pnpm lint:check | ✅ 0 errors, 2 pre-existing warnings |
pnpm test | ✅ 797 files / 4329 tests |
The 500 on /api/artists is that route throwing STRIPE_SK environment variable is required in my shell — application code, reached through the proxy, which is the point.
The 402 payload 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_ADDRESS differ 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@16 and removed the deprecated runtime config. Fixes the dev warning and keeps the x402 payment challenge unchanged.
- Refactors
- Renamed
middleware.tstoproxy.tsand changed export frommiddlewaretoproxy. - Removed
runtime: "nodejs"from config;matcherunchanged. - Verified: proxy runs in dev; unpaid
GET /api/x402/image/generatereturns the same 402; build, lint, and tests pass.
- Renamed