Skip to content

Detect middleware runtime and conditionally handle Node middleware for Cloudflare build#1

Draft
314systems wants to merge 1 commit into
mainfrom
codex/investigate-node-vs-edge-middleware-compatibility
Draft

Detect middleware runtime and conditionally handle Node middleware for Cloudflare build#1
314systems wants to merge 1 commit into
mainfrom
codex/investigate-node-vs-edge-middleware-compatibility

Conversation

@314systems
Copy link
Copy Markdown
Owner

Motivation

  • Allow newer Next.js builds (15.5+) that ship Node-style middleware/proxy to be detected and not fail the Cloudflare build.
  • Avoid unconditional removal of Node middleware and instead make patching conditional based on the detected Next.js output and version.

Description

  • Replaced useNodeMiddleware with detectMiddlewareRuntime which returns one of "edge", "node", or "none" by inspecting compiled Next output manifests.
  • Updated build.ts to call detectMiddlewareRuntime and to log an informational message when Node middleware is detected instead of erroring and exiting.
  • Adjusted next-server AST patching so the disableNodeMiddlewareRule is applied only for Next.js versions less than 15.5.0 using compareSemver.
  • Added middleware.spec.ts unit tests for detectMiddlewareRuntime and updated related imports and comments explaining why internal patches remain in place.

Testing

  • Ran unit tests with vitest, including the new packages/cloudflare/src/cli/build/utils/middleware.spec.ts, and all tests passed.
  • Existing patch/unit specs that exercise next-server patches were executed and succeeded under the test suite.

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant