Proxy設定(Node.js)
若要設定Node SDK之HTTP請求的Proxy,請覆寫SDK在初始化期間使用的擷取API。
下列是基本範例,說明如何在TargetClient
初始化期間覆寫fetchApi
以新增Proxy:
const { ProxyAgent } = require("undici");
const proxyAgent = new ProxyAgent("your proxy address here");
const fetchImpl = (url, options) => {
const fetchOptions = options;
fetchOptions.dispatcher = proxyAgent;
return fetch(url, fetchOptions);
};
client = TargetClient.create({
...,
fetchApi: fetchImpl
});
請注意,這僅適用於節點版本18.2+,其中undici.fetch
是節點的預設fetch
。
請造訪Node SDK範例存放庫
舊版節點的proxy設定範例及詳細資訊。
recommendation-more-help
6906415f-169c-422b-89d3-7118e147c4e3