Repository navigation
Add experimental native Go proxy support - #101464
Conversation
Tests PassedCommit: e6ba212 |
|
Vercel Agent finished reviewing your changes. Vercel Agent's latest review does not approve this pull request under the repository's review policy. Resolved issues (2)
Review steps (1m 6s)Preparing the workspace 34.3s |
…as before. Go proxies express an empty header replacement with an internal override name instead, so their semantics and Flight header preservation are unchanged. Only detect proxy.go when experimental.goRoutes is enabled, and only fail on multiple Proxy files when one of them is proxy.go. Multiple JavaScript Proxy files keep resolving as before. Combine Go request-header values whose names differ only in case, and use the first X-Forwarded-Proto entry when resolving relative destinations. Co-authored-by: vercel-v[bot] <353008837+vercel-v[bot]@users.noreply.github.com>
Co-authored-by: vercel-v[bot] <353008837+vercel-v[bot]@users.noreply.github.com>
Co-authored-by: vercel-v[bot] <353008837+vercel-v[bot]@users.noreply.github.com>
Co-authored-by: vercel-v[bot] <353008837+vercel-v[bot]@users.noreply.github.com>
Co-authored-by: vercel-v[bot] <353008837+vercel-v[bot]@users.noreply.github.com>
Co-authored-by: vercel-v[bot] <353008837+vercel-v[bot]@users.noreply.github.com>
Co-authored-by: vercel-v[bot] <353008837+vercel-v[bot]@users.noreply.github.com>
Resolve conflicts with #101464 (experimental native Go proxy). Canary's dev router now needs a runtime for the proxy (edge, nodejs or go) and gets it from the route watcher, which this branch no longer runs in Turbopack dev. Turbopack dev now sets it in handleEntrypoints: - a native written endpoint means a proxy.go, with canary's middleware.native.json entry; - otherwise the Edge middleware manifest decides between edge and nodejs, because Turbopack reports every JavaScript middleware endpoint as Edge. The watcher's "Multiple Proxy files detected" check moves into the Turbopack root-file diagnostics: with experimental.goRoutes, proxy.go and src/proxy.go are candidates, in native middleware_files order, and a Go proxy next to another Proxy file is reported. Go files skip the JavaScript config validation. The hot reloader conflict needed no change: this branch already skips /proxy and /src/proxy.
| &serde_json::to_string(&route_pattern)?, | ||
| ); | ||
| let handler = if is_proxy { | ||
| include_str!("templates/go_proxy_handler.go").to_owned() |
There was a problem hiding this comment.
It's a bit unexpected that this is a "template" since there is nothing to replace here, but seems fine...
| if (isAppDir && normalizedPagePath.endsWith('/route')) { | ||
| pagePaths.push(normalizedPagePath.slice(1) + '.go') | ||
| } |
There was a problem hiding this comment.
Why does route.go doesn't require experimental.goRoutes?
| folder: string, | ||
| extensions: string[] | ||
| extensions: string[], | ||
| goRoutes = false |
There was a problem hiding this comment.
These optional arguments are very easy to forget...
Co-authored-by: vercel-v[bot] <353008837+vercel-v[bot]@users.noreply.github.com>
Summary
Add
proxy.goandsrc/proxy.gowith aProxy(http.ResponseWriter, *http.Request)handler.experimental.goRoutes: trueenables both Go routes and proxies. This first version matches all paths and uses deployment defaults; file-local configuration follows in #101551. Turbopack compiles the handler into a native HTTP worker fornext devandnext start, with continuation, rewrites, redirects, request-header overrides, cookies, body replay, and streaming responses.Adapter builds emit a
MIDDLEWAREoutput withruntime: 'go'and a PORT-based executable. Hosted rollout also requires Go middleware packaging in adapter-vercel #156 and proxy-only build preparation in@vercel/next.Go directory snapshots now respect the filesystem's denied paths, allowing a project-root proxy to compile alongside excluded
.nextoutput directories.Differences from JavaScript proxies
ProxyOptions.Request.Headers(http.Header{}) removes every downstream request header, while anilmap preserves them. In JavaScript,NextResponse.next({ request: { headers: new Headers() } })is a no-op and the incoming headers are kept. Go expresses the empty replacement with an internal override name (x-next-internal-go-empty-override) so the JavaScript behavior is unchanged; Flight headers are still preserved. How the Vercel platform handles that override name is not verified yet, since hosted Go proxies depend on the companion adapter and builder changes.Verification
A second differential pass covered 218 production pairs, 20 reduced method/scenario groups, and five stream/error checks. Fixed missing body framing on the hop into Go routes after header overrides or client chunking, with method-by-method continuation/rewrite/follow-up-request coverage.
Differential routing fuzzing covered 340 paired Go/JavaScript cases. Reduced production comparisons now match after fixes for encoded relative URLs, streamed DELETE/OPTIONS bodies, and downstream Date preservation.
Confirmed JSON/form Pages API body parsing and 600 KiB body replay; documented the ordinary Response versus NextResponse cookie-helper distinction.
Production, development, and Cache Components HTTP coverage passed, including root/src layouts and interoperability with Go route handlers.
Executed the emitted adapter server without Next.js to verify its PORT-based HTTP contract.
cargo test -p turbopack-go --test live -- --test-threads=2— 12 passed, including directory exclusion, invalidation, and cache regressions.Native route discovery/transport coverage, TypeScript, ESLint, and formatting checks passed.
Live Vercel deployment has not been verified. Deploy CI is gated until the companion adapter and builder changes are released and selected by the harness; the released builder does not provision Go for proxy-only apps.
Shared-flag config coverage, native route/proxy production suites, proxy development mode, and Cache Components checks pass.
Isolated public-type consumers and server trace snapshots pass. Go data-request URLs are covered with URL normalization enabled and disabled.