rsnext/test/integration/middleware
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
..
core Fix running server with Polyfilled fetch (#31935) 2021-12-03 16:35:28 +00:00
hmr Fix HMR for middleware #30791 (#31548) 2021-11-18 18:23:52 +00:00
with-base-path fix(31013): add base path to preflight request url (#31101) 2021-11-09 19:03:05 +00:00
with-eval run middleware parser handler only for middleware modules (#31219) 2021-11-10 15:31:46 +00:00
with-i18n Fix middleware i18n rewrites (#31174) 2021-11-09 01:28:39 +00:00