-
Notifications
You must be signed in to change notification settings - Fork 27.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Revert #49138 and split the server-ipc file into smaller modules.
- Loading branch information
Showing
11 changed files
with
215 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { IncomingMessage } from 'http' | ||
import { filterReqHeaders } from './utils' | ||
|
||
export const invokeRequest = async ( | ||
targetUrl: string, | ||
requestInit: { | ||
headers: IncomingMessage['headers'] | ||
method: IncomingMessage['method'] | ||
}, | ||
readableBody?: import('stream').Readable | ||
) => { | ||
const parsedUrl = new URL(targetUrl) | ||
|
||
// force localhost to IPv4 as some DNS may | ||
// resolve to IPv6 instead | ||
if (parsedUrl.hostname === 'localhost') { | ||
parsedUrl.hostname = '127.0.0.1' | ||
} | ||
const invokeHeaders = filterReqHeaders({ | ||
...requestInit.headers, | ||
}) as IncomingMessage['headers'] | ||
|
||
const invokeRes = await new Promise<IncomingMessage>( | ||
(resolveInvoke, rejectInvoke) => { | ||
const http = require('http') as typeof import('http') | ||
|
||
try { | ||
const invokeReq = http.request( | ||
targetUrl, | ||
{ | ||
headers: invokeHeaders, | ||
method: requestInit.method, | ||
}, | ||
(res) => { | ||
resolveInvoke(res) | ||
} | ||
) | ||
invokeReq.on('error', (err) => { | ||
rejectInvoke(err) | ||
}) | ||
|
||
if (requestInit.method !== 'GET' && requestInit.method !== 'HEAD') { | ||
if (readableBody) { | ||
readableBody.pipe(invokeReq) | ||
readableBody.on('close', () => { | ||
invokeReq.end() | ||
}) | ||
} | ||
} else { | ||
invokeReq.end() | ||
} | ||
} catch (err) { | ||
rejectInvoke(err) | ||
} | ||
} | ||
) | ||
|
||
return invokeRes | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const forbiddenHeaders = [ | ||
'accept-encoding', | ||
'content-length', | ||
'keepalive', | ||
'content-encoding', | ||
'transfer-encoding', | ||
// https://github.com/nodejs/undici/issues/1470 | ||
'connection', | ||
] | ||
|
||
export const filterReqHeaders = ( | ||
headers: Record<string, undefined | string | string[]> | ||
) => { | ||
for (const [key, value] of Object.entries(headers)) { | ||
if ( | ||
forbiddenHeaders.includes(key) || | ||
!(Array.isArray(value) || typeof value === 'string') | ||
) { | ||
delete headers[key] | ||
} | ||
} | ||
return headers | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default function Root({ children }) { | ||
return ( | ||
<html> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export default async function Page() { | ||
const data = Math.random() | ||
return <h1>{data}</h1> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
experimental: { | ||
appDir: true, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export default async function (_req, res) { | ||
try { | ||
await res.revalidate('/') | ||
return res.json({ revalidated: true }) | ||
} catch (err) { | ||
return res.status(500).send('Error') | ||
} | ||
} |
Oops, something went wrong.