rsnext/test/integration/middleware/core
Javi Velasco 1c199a5e4a
Fix running server with Polyfilled fetch (#31935)
This PR fixes #30398

By default Next will polyfill some fetch APIs (Request, Response, Header and fetch) only if fetch is not found in the global scope in certain entry points. If we have a custom server which is adding a global fetch (and only fetch) at the very top then the rest of APIs will not be polyfilled.

This PR adds a test on the custom server where we can add a custom polyfill for fetch with an env variable. This reproduces the issue since next-server.js will be required without having a polyfill for Response which makes it fail on requiring NextResponse. Then we remove the code that checks for subrequests to happen within the **sandbox** so that we don't need to polyfill `next-server` anymore.

The we also introduce an improvement on how we handle relative requests. Since #31858 introduced a `port` and `hostname` options for the server, we can always pass absolute URLs to the Middleware so we can always use the original `nextUrl` to pass it to fetch. This brings a lot of simplification for `NextURL` since we don't have to consider relative URLs no more.

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Errors have helpful link attached, see `contributing.md`
2021-12-03 16:35:28 +00:00
..
lib Update middleware eval checks (#30883) 2021-11-05 20:48:43 +00:00
pages Fix running server with Polyfilled fetch (#31935) 2021-12-03 16:35:28 +00:00
test Fix running server with Polyfilled fetch (#31935) 2021-12-03 16:35:28 +00:00
next.config.js Update middleware eval checks (#30883) 2021-11-05 20:48:43 +00:00