This repository has been archived by the owner on Jun 21, 2023. It is now read-only.
forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…7709) Follow up to vercel#27376 so users can disable keep-alive. See comment vercel#27376 (comment)
- Loading branch information
Showing
13 changed files
with
189 additions
and
44 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
docs/api-reference/next.config.js/disabling-http-keep-alive.md
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,36 @@ | ||
--- | ||
description: Next.js will automatically use HTTP Keep-Alive by default. Learn more about how to disable HTTP Keep-Alive here. | ||
--- | ||
|
||
# Disabling HTTP Keep-Alive | ||
|
||
Next.js automatically polyfills [node-fetch](/docs/basic-features/supported-browsers-features#polyfills) and enables [HTTP Keep-Alive](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Keep-Alive) by default. You may want to disable HTTP Keep-Alive for certain `fetch()` calls or globally. | ||
|
||
For a single `fetch()` call, you can add the agent option: | ||
|
||
```js | ||
import { Agent } from 'https' | ||
|
||
const url = 'https://example.com' | ||
const agent = new Agent({ keepAlive: false }) | ||
fetch(url, { agent }) | ||
``` | ||
|
||
To override all `fetch()` calls globally, you can use `next.config.js`: | ||
|
||
```js | ||
module.exports = { | ||
httpAgentOptions: { | ||
keepAlive: false, | ||
}, | ||
} | ||
``` | ||
|
||
## Related | ||
|
||
<div class="card"> | ||
<a href="/docs/api-reference/next.config.js/introduction.md"> | ||
<b>Introduction to next.config.js:</b> | ||
<small>Learn more about the configuration file used by Next.js.</small> | ||
</a> | ||
</div> |
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
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
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
23 changes: 23 additions & 0 deletions
23
test/integration/node-fetch-keep-alive/pages/blog/[slug].js
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 @@ | ||
export default function Blog(props) { | ||
return <pre id="props">{JSON.stringify(props)}</pre> | ||
} | ||
|
||
export async function getStaticProps({ params: { slug } }) { | ||
return { props: { slug } } | ||
} | ||
|
||
export async function getStaticPaths() { | ||
const res = await fetch('http://localhost:44001') | ||
const obj = await res.json() | ||
if (obj.connection === 'keep-alive') { | ||
return { | ||
paths: [{ params: { slug: 'first' } }], | ||
fallback: false, | ||
} | ||
} | ||
|
||
return { | ||
paths: [], | ||
fallback: false, | ||
} | ||
} |
Oops, something went wrong.