Skip to content

Commit

Permalink
Ensure fetch polyfill is loaded in next-server (#33616)
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Jan 24, 2022
1 parent 9a2d97c commit e8c15e5
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/next/build/utils.ts
@@ -1,3 +1,4 @@
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'
Expand Down
1 change: 1 addition & 0 deletions packages/next/server/next-server.ts
@@ -1,3 +1,4 @@
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'
Expand Down
@@ -1,7 +1,9 @@
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()),
})
}
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions test/production/required-server-files/pages/gssp.js
Expand Up @@ -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()),
},
}
}
Expand Down

0 comments on commit e8c15e5

Please sign in to comment.