| 99 | } |
| 100 | |
| 101 | export function fetchViaHTTP(appPort, pathname, query, opts) { |
| 102 | const url = `${pathname}${ |
| 103 | typeof query === "string" ? query : query ? `?${qs.stringify(query)}` : "" |
| 104 | }` |
| 105 | return fetch(getFullUrl(appPort, url), { |
| 106 | // in node.js v17 fetch favors IPv6 but Next.js is |
| 107 | // listening on IPv4 by default so force IPv4 DNS resolving |
| 108 | agent: (parsedUrl) => { |
| 109 | if (parsedUrl.protocol === "https:") { |
| 110 | return new https.Agent({family: 4}) |
| 111 | } |
| 112 | if (parsedUrl.protocol === "http:") { |
| 113 | return new http.Agent({family: 4}) |
| 114 | } |
| 115 | }, |
| 116 | ...opts, |
| 117 | }) |
| 118 | } |
| 119 | |
| 120 | export function findPort() { |
| 121 | return getPort() |