Restrict proxy.go to App Router applications (#102011)
Restricts `proxy.go` to App Router applications and makes the URL it
receives match what `proxy.ts` receives.
**Changes**
- `proxy.go` fails to build when the project has Pages Router routes
(pages or API routes in `pages`) or sets `i18n`. Custom `_app`,
`_document` and `_error` files are allowed. In development, the error is
also printed in the terminal.
- In adapter builds, the Go handler applies the same URL normalization
the JavaScript adapter applies before `proxy.ts` runs, so `r.URL` and
`r.RequestURI` match `request.url`. Under `next start`, Next.js already
forwards that URL, and the Go handler leaves it unchanged.
- Docs updated.
**Validation**
- `pnpm test-start-turbo` and `pnpm test-dev-turbo` on
`test/e2e/app-dir/native-proxy-go` pass. Tests cover:
- Build errors for Pages Router routes (including `src/pages` with
`src/proxy.go`) and `i18n`, and errors appearing and clearing while
`next dev` runs.
- `route.go` alongside the Pages Router without `proxy.go`.
- The URLs `proxy.go` receives under `next start` and as an
adapter-built executable, compared with `proxy.ts`, for the default
config, `basePath`, `trailingSlash`, and `skipProxyUrlNormalize`.
- `test/unit/native-proxy-go/url-parity.test.ts` compiles the Go handler
and compares it with the JavaScript adapter on generated URLs (paths,
queries, `basePath`, `trailingSlash`, `skipProxyUrlNormalize`).
- `cargo test -p next-api` and `cargo clippy -p next-api --tests` pass.
---------
Co-authored-by: vercel-v[bot] <353008837+vercel-v[bot]@users.noreply.github.com>
Co-authored-by: Tim Neutkens <6324199+timneutkens@users.noreply.github.com>