diff options
author | 2022-09-22 13:47:06 -0500 | |
---|---|---|
committer | 2022-09-22 14:47:06 -0400 | |
commit | 5e4c5252bd80cbaf6a7ee4d4503ece007664410f (patch) | |
tree | e209fdf5e4a0514d90ceb4289d56c5a835126df3 /packages/webapi | |
parent | 6ce8ae261f71ae301f70480b207fbb18eb71af75 (diff) | |
download | astro-5e4c5252bd80cbaf6a7ee4d4503ece007664410f.tar.gz astro-5e4c5252bd80cbaf6a7ee4d4503ece007664410f.tar.zst astro-5e4c5252bd80cbaf6a7ee4d4503ece007664410f.zip |
Http proxy for fetch (#4676)
* 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`
Diffstat (limited to 'packages/webapi')
-rw-r--r-- | packages/webapi/package.json | 2 | ||||
-rw-r--r-- | packages/webapi/run/build.js | 2 | ||||
-rw-r--r-- | packages/webapi/src/lib/fetch.ts | 7 |
3 files changed, 10 insertions, 1 deletions
diff --git a/packages/webapi/package.json b/packages/webapi/package.json index 1d8727c25..5b94c4429 100644 --- a/packages/webapi/package.json +++ b/packages/webapi/package.json @@ -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": { @@ -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", diff --git a/packages/webapi/run/build.js b/packages/webapi/run/build.js index d81f5e609..42571763a 100644 --- a/packages/webapi/run/build.js +++ b/packages/webapi/run/build.js @@ -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) }, diff --git a/packages/webapi/src/lib/fetch.ts b/packages/webapi/src/lib/fetch.ts index b099e44af..9c1f7c446 100644 --- a/packages/webapi/src/lib/fetch.ts +++ b/packages/webapi/src/lib/fetch.ts @@ -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 } |