Unverified Commit e8c15e59 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Ensure fetch polyfill is loaded in next-server (#33616)

parent 9a2d97cc
import '../server/node-polyfill-fetch'
import chalk from 'next/dist/compiled/chalk'
import getGzipSize from 'next/dist/compiled/gzip-size'
import textTable from 'next/dist/compiled/text-table'
......
import './node-polyfill-fetch'
import type { Params, Route } from './router'
import type { CacheFs } from '../shared/lib/utils'
import type { MiddlewareManifest } from '../build/webpack/plugins/middleware-plugin'
......
export default (req, res) => {
export default async (req, res) => {
console.log(req.url, 'query', req.query)
res.json({
url: req.url,
query: req.query,
// make sure fetch if polyfilled
example: await fetch('https://example.com').then((res) => res.text()),
})
}
......@@ -10,7 +10,10 @@ export const getStaticProps = ({ params }) => {
}
}
export const getStaticPaths = () => {
export const getStaticPaths = async () => {
// make sure fetch if polyfilled
await fetch('https://example.com').then((res) => res.text())
return {
paths: ['/fallback/first'],
fallback: true,
......
......@@ -19,6 +19,8 @@ export async function getServerSideProps({ res }) {
props: {
hello: 'world',
data,
// make sure fetch if polyfilled
example: await fetch('https://example.com').then((res) => res.text()),
},
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment