cloudflare/vinext

Pages Router: API route returns 500 when middleware is present

Geschlossen

#1.477 geöffnet am 22.05.2026

 (0 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)TypeScript (371 Forks)github user discovery
adapter-api-e2ehelp wanted

Repository-Metriken

Stars
 (8.563 Sterne)
PR-Merge-Metriken
 (Durchschn. Merge 1T 1h) (462 gemergte PRs in 30 T)

Beschreibung

This issue was created by an agent analysing CI failures from the Next.js Deploy Suite (vinext main vs Next.js v16.2.6, 2026-05-22).

Problem

When a Pages Router app defines middleware and a client makes a request to /api/*, the API handler returns Internal Server Error (HTTP 500) instead of executing. The middleware pipeline appears to interfere with API route dispatch.

GET /api/* with middleware returns 500

Estimated Impact

~2 test failures across the deploy suite.

Affected Test Suites

  • test/e2e/proxy-request-with-middleware/test/index.test.ts (2 failures)

Recommendation

  1. Reproduce first in vinext's own test suite. Add a Pages Router fixture with a no-op middleware.ts and pages/api/hello.ts. Assert /api/hello returns 200.

  2. Fix the middleware -> API route handoff. After middleware runs and chooses to fall through (no rewrite/redirect), /api/* routes must dispatch normally instead of crashing.

  3. Related, but not duplicate, of #1338. #1338 covers edge runtime API routes returning 500/404; this is node runtime API routes returning 500 specifically because middleware is configured.

Contributor Guide