support HTTP proxies

This commit is contained in:
Jannis R 2020-09-21 13:18:31 +02:00
parent fddf25a429
commit de86391dcd
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
2 changed files with 6 additions and 0 deletions

View file

@ -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),

View file

@ -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",