mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-04-20 23:23:56 +03:00
more reliable setup of proxy agent
Some checks failed
test / lint-and-spellcheck (push) Has been cancelled
test / unit-tests (18.x) (push) Has been cancelled
test / unit-tests (20.x) (push) Has been cancelled
test / unit-tests (22.x) (push) Has been cancelled
test / integration-tests (18.x) (push) Has been cancelled
test / integration-tests (20.x) (push) Has been cancelled
test / integration-tests (22.x) (push) Has been cancelled
test / e2e-tests (18.x) (push) Has been cancelled
Some checks failed
test / lint-and-spellcheck (push) Has been cancelled
test / unit-tests (18.x) (push) Has been cancelled
test / unit-tests (20.x) (push) Has been cancelled
test / unit-tests (22.x) (push) Has been cancelled
test / integration-tests (18.x) (push) Has been cancelled
test / integration-tests (20.x) (push) Has been cancelled
test / integration-tests (22.x) (push) Has been cancelled
test / e2e-tests (18.x) (push) Has been cancelled
This commit is contained in:
parent
960371e2ec
commit
9975a6c9ac
1 changed files with 6 additions and 4 deletions
|
@ -7,15 +7,16 @@ const proxyAddress = typeof process !== 'undefined' && (process.env.HTTPS_PROXY
|
|||
|
||||
let getAgent = () => undefined;
|
||||
|
||||
if (proxyAddress) {
|
||||
import('https-proxy-agent').then(a => {
|
||||
const setupProxy = async () => {
|
||||
if (proxyAddress && !getAgent()) {
|
||||
const a = await import('https-proxy-agent');
|
||||
const agent = new a.default.HttpsProxyAgent(proxyAddress, {
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 10 * 1000, // 10s
|
||||
});
|
||||
getAgent = () => agent;
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const randomBytesHexString = length => [...Array(length)].map(() => Math.floor(Math.random() * 16)
|
||||
.toString(16))
|
||||
|
@ -74,6 +75,7 @@ const checkIfResponseIsOk = (_) => {
|
|||
|
||||
const request = async (ctx, userAgent, reqData) => {
|
||||
const {profile, opt} = ctx;
|
||||
await setupProxy();
|
||||
|
||||
const endpoint = reqData.endpoint;
|
||||
delete reqData.endpoint;
|
||||
|
|
Loading…
Add table
Reference in a new issue