diff --git a/lib/request.js b/lib/request.js index 174c84e6..2a0ae903 100644 --- a/lib/request.js +++ b/lib/request.js @@ -7,10 +7,14 @@ const {randomBytes} = require('crypto') const createHash = require('create-hash') const captureStackTrace = DEV ? require('capture-stack-trace') : () => {} const {stringify} = require('qs') +const ProxyAgent = require('https-proxy-agent') const Promise = require('pinkie-promise') const {fetch} = require('fetch-ponyfill')({Promise}) const {addErrorInfo} = require('./errors') +const proxyAddress = process.env.HTTPS_PROXY || process.env.HTTP_PROXY || null +const proxyAgent = proxyAddress ? new ProxyAgent(proxyAddress) : null + const id = randomBytes(6).toString('hex') const randomizeUserAgent = (userAgent) => { const i = Math.round(Math.random() * userAgent.length) @@ -31,6 +35,7 @@ const request = (ctx, userAgent, reqData) => { if (DEBUG) console.error(JSON.stringify(body)) const req = profile.transformReq(ctx, { + agent: proxyAgent, method: 'post', // todo: CORS? referrer policy? body: JSON.stringify(body), diff --git a/package.json b/package.json index 57db281a..2bd8d342 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,7 @@ "fetch-ponyfill": "^6.0.0", "google-polyline": "^1.0.3", "gps-distance": "0.0.4", + "https-proxy-agent": "^5.0.0", "lodash": "^4.17.5", "luxon": "^1.3.0", "object-scan": "^13.0.0",