mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 07:09:35 +02:00
support HTTP proxies
This commit is contained in:
parent
fddf25a429
commit
de86391dcd
2 changed files with 6 additions and 0 deletions
|
@ -7,10 +7,14 @@ const {randomBytes} = require('crypto')
|
||||||
const createHash = require('create-hash')
|
const createHash = require('create-hash')
|
||||||
const captureStackTrace = DEV ? require('capture-stack-trace') : () => {}
|
const captureStackTrace = DEV ? require('capture-stack-trace') : () => {}
|
||||||
const {stringify} = require('qs')
|
const {stringify} = require('qs')
|
||||||
|
const ProxyAgent = require('https-proxy-agent')
|
||||||
const Promise = require('pinkie-promise')
|
const Promise = require('pinkie-promise')
|
||||||
const {fetch} = require('fetch-ponyfill')({Promise})
|
const {fetch} = require('fetch-ponyfill')({Promise})
|
||||||
const {addErrorInfo} = require('./errors')
|
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 id = randomBytes(6).toString('hex')
|
||||||
const randomizeUserAgent = (userAgent) => {
|
const randomizeUserAgent = (userAgent) => {
|
||||||
const i = Math.round(Math.random() * userAgent.length)
|
const i = Math.round(Math.random() * userAgent.length)
|
||||||
|
@ -31,6 +35,7 @@ const request = (ctx, userAgent, reqData) => {
|
||||||
if (DEBUG) console.error(JSON.stringify(body))
|
if (DEBUG) console.error(JSON.stringify(body))
|
||||||
|
|
||||||
const req = profile.transformReq(ctx, {
|
const req = profile.transformReq(ctx, {
|
||||||
|
agent: proxyAgent,
|
||||||
method: 'post',
|
method: 'post',
|
||||||
// todo: CORS? referrer policy?
|
// todo: CORS? referrer policy?
|
||||||
body: JSON.stringify(body),
|
body: JSON.stringify(body),
|
||||||
|
|
|
@ -43,6 +43,7 @@
|
||||||
"fetch-ponyfill": "^6.0.0",
|
"fetch-ponyfill": "^6.0.0",
|
||||||
"google-polyline": "^1.0.3",
|
"google-polyline": "^1.0.3",
|
||||||
"gps-distance": "0.0.4",
|
"gps-distance": "0.0.4",
|
||||||
|
"https-proxy-agent": "^5.0.0",
|
||||||
"lodash": "^4.17.5",
|
"lodash": "^4.17.5",
|
||||||
"luxon": "^1.3.0",
|
"luxon": "^1.3.0",
|
||||||
"object-scan": "^13.0.0",
|
"object-scan": "^13.0.0",
|
||||||
|
|
Loading…
Add table
Reference in a new issue