From 61e575349da4684ab6d31ec6c81987e8c334aa38 Mon Sep 17 00:00:00 2001 From: yunsen Date: Mon, 28 Mar 2022 21:43:29 +0800 Subject: [PATCH] support proxy through `https-proxy-agent` --- README.md | 12 ++++++++++++ src/util.js | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 29503ea..d6ef73c 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,18 @@ wiki({ }).search('Winterfell'); ``` +## Usage with Proxy +You can use proxy with `https-proxy-agent` +```js +const HttpsProxyAgent = require('https-proxy-agent') + +wiki({agent: new HttpsProxyAgent('http://address:port')}) + .page('Batman') + .then(page => page.info('alterEgo')) + .then(console.log) // Bruce Wayne + +``` + ## Chain data requests together for more efficient applications Query a specific page: diff --git a/src/util.js b/src/util.js index 5eb6252..f9922db 100644 --- a/src/util.js +++ b/src/util.js @@ -30,7 +30,7 @@ export function api(apiOptions, params = {}) { { 'User-Agent': 'WikiJS Bot v1.0' }, apiOptions.headers ); - return fetch(url, Object.assign({ headers }, fetchOptions)) + return fetch(url, Object.assign({ headers }, fetchOptions, {agent: apiOptions.agent})) .then(res => { if (res.ok) { return res.json();