mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
This enhances the current parsing completed by Next.js of configuration from app segments. Previously a collection of fragile checks was used to parse the different segment configuration options which performed no validation on the inputs. This uses the `zod` library (which we already use internally) to perform validation on the configuration exported. A followup PR #70480 will add more verbose error logging around the validation errors.
82 lines
2.0 KiB
JavaScript
82 lines
2.0 KiB
JavaScript
import { fetchRetry } from '../../../lib/fetch-retry'
|
|
|
|
export const runtime = 'edge'
|
|
|
|
export default async function Page() {
|
|
const data = await fetchRetry(
|
|
'https://next-data-api-endpoint.vercel.app/api/random',
|
|
{
|
|
method: 'POST',
|
|
next: {
|
|
revalidate: 10,
|
|
},
|
|
}
|
|
).then((res) => res.text())
|
|
|
|
const dataWithBody1 = await fetchRetry(
|
|
'https://next-data-api-endpoint.vercel.app/api/random',
|
|
{
|
|
method: 'POST',
|
|
body: JSON.stringify({ hello: 'world' }),
|
|
next: {
|
|
revalidate: 10,
|
|
},
|
|
}
|
|
).then((res) => res.text())
|
|
|
|
const dataWithBody2 = await fetchRetry(
|
|
'https://next-data-api-endpoint.vercel.app/api/random',
|
|
{
|
|
method: 'POST',
|
|
body: new ReadableStream({
|
|
start(controller) {
|
|
controller.enqueue(JSON.stringify({ another: 'one' }))
|
|
controller.close()
|
|
},
|
|
}),
|
|
duplex: 'half',
|
|
next: {
|
|
revalidate: 10,
|
|
},
|
|
}
|
|
).then((res) => res.text())
|
|
|
|
const formData = new FormData()
|
|
formData.append('hello', 'value')
|
|
formData.append('another', new Blob(['some text'], { type: 'text/plain' }))
|
|
formData.append('another', 'text')
|
|
|
|
const dataWithBody3 = await fetchRetry(
|
|
'https://next-data-api-endpoint.vercel.app/api/random',
|
|
{
|
|
method: 'POST',
|
|
body: formData,
|
|
next: {
|
|
revalidate: 10,
|
|
},
|
|
}
|
|
).then((res) => res.text())
|
|
|
|
const dataWithBody4 = await fetchRetry(
|
|
'https://next-data-api-endpoint.vercel.app/api/random',
|
|
{
|
|
method: 'POST',
|
|
body: new URLSearchParams('myParam=myValue&myParam=anotherValue'),
|
|
next: {
|
|
revalidate: 30,
|
|
},
|
|
}
|
|
).then((res) => res.text())
|
|
|
|
return (
|
|
<>
|
|
<p id="page">/variable-revalidate/post-method-cached</p>
|
|
<p id="page-data">{data}</p>
|
|
<p id="data-body1">{dataWithBody1}</p>
|
|
<p id="data-body2">{dataWithBody2}</p>
|
|
<p id="data-body3">{dataWithBody3}</p>
|
|
<p id="data-body4">{dataWithBody4}</p>
|
|
</>
|
|
)
|
|
}
|