Skip to content

Commit

Permalink
Http proxy for fetch (#4676)
Browse files Browse the repository at this point in the history
* Add HTTP Proxy Support to `fetch` Polyfill

Use `global-agent` to support HTTP_PROXY, HTTPS_PROXY, and NO_PROXY
environment variables.

* Add Changeset For HTTP Proxy Support in `fetch`
  • Loading branch information
zicklag committed Sep 22, 2022
1 parent 6ce8ae2 commit 5e4c525
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/curvy-needles-boil.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/webapi': minor
---

Add HTTP Proxy Support to `fetch` Polyfill
2 changes: 2 additions & 0 deletions packages/webapi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"bugs": "https://github.com/withastro/astro/issues",
"homepage": "https://github.com/withastro/astro/tree/main/packages/webapi#readme",
"dependencies": {
"global-agent": "^3.0.0",
"node-fetch": "^3.2.5"
},
"devDependencies": {
Expand All @@ -58,6 +59,7 @@
"@rollup/plugin-node-resolve": "^13.3.0",
"@rollup/plugin-typescript": "^8.3.2",
"@types/chai": "^4.3.1",
"@types/global-agent": "^2.1.1",
"@types/mocha": "^9.1.1",
"@types/node": "^14.18.21",
"@ungap/structured-clone": "^0.3.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/webapi/run/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ async function build() {
inputOptions: {
input: 'src/polyfill.ts',
plugins: plugins,
external: ['node-fetch'],
external: ['node-fetch', 'global-agent'],
onwarn(warning, warn) {
if (warning.code !== 'UNRESOLVED_IMPORT') warn(warning)
},
Expand Down
7 changes: 7 additions & 0 deletions packages/webapi/src/lib/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ import type { RequestInit } from 'node-fetch'
import { default as nodeFetch, Headers, Request, Response } from 'node-fetch'
import Stream from 'node:stream'
import * as _ from './utils'
import {
bootstrap as bootstrapGlobalAgent
} from 'global-agent';

bootstrapGlobalAgent({
environmentVariableNamespace: '',
});

export { Headers, Request, Response }

Expand Down
78 changes: 77 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5e4c525

Please sign in to comment.