mirror of
https://github.com/vercel/next.js.git
synced 2026-09-20 02:25:18 +08:00
37 lines
836 B
TypeScript
37 lines
836 B
TypeScript
import React from 'react'
|
|
import { ReactNode } from 'react'
|
|
|
|
const magicNumber = Math.random()
|
|
const originalFetch = globalThis.fetch
|
|
|
|
if (originalFetch.name === 'monkeyPatchedFetch') {
|
|
throw new Error(
|
|
'Patching over already patched fetch. This creates a memory leak.'
|
|
)
|
|
}
|
|
|
|
globalThis.fetch = async function monkeyPatchedFetch(
|
|
resource: URL | RequestInfo,
|
|
options?: RequestInit
|
|
) {
|
|
const request = new Request(resource)
|
|
|
|
if (request.url === 'http://fake.url/secret') {
|
|
return new Response('monkey patching is fun')
|
|
}
|
|
|
|
if (request.url === 'http://fake.url/magic-number') {
|
|
return new Response(magicNumber.toString())
|
|
}
|
|
|
|
return originalFetch(resource, options)
|
|
}
|
|
|
|
export default function Root({ children }: { children: ReactNode }) {
|
|
return (
|
|
<html>
|
|
<body>{children}</body>
|
|
</html>
|
|
)
|
|
}
|