Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 32 additions & 24 deletions lib/proxy-factory.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,37 @@
'use strict'

const fastProxy = require('fast-proxy-lite')
module.exports = (() => {
let fastProxyLite, httpLambdaProxy, fastProxyLegacy

module.exports = ({ proxyType, opts, route }) => {
let proxy
return ({ proxyType, opts, route }) => {
const base = opts.targetOverride || route.target
const config = route.proxyConfig || {}

if (proxyType === 'http') {
proxy = fastProxy({
base: opts.targetOverride || route.target,
...route.proxyConfig
}).proxy
} else if (proxyType === 'lambda') {
proxy = require('http-lambda-proxy')({
target: opts.targetOverride || route.target,
region: 'eu-central-1',
...route.proxyConfig
})
} else if (proxyType === 'http-legacy') {
proxy = require('fast-proxy')({
base: opts.targetOverride || route.target,
...route.proxyConfig
}).proxy
} else {
throw new Error(`Unsupported proxy type: ${proxyType}!`)
}
switch (proxyType) {
case 'http':
fastProxyLite = fastProxyLite || require('fast-proxy-lite')
return fastProxyLite({
base,
...config
}).proxy

case 'lambda':
httpLambdaProxy = httpLambdaProxy || require('http-lambda-proxy')
return httpLambdaProxy({
target: base,
region: 'eu-central-1',
...config
})

return proxy
}
case 'http-legacy':
fastProxyLegacy = fastProxyLegacy || require('fast-proxy')
return fastProxyLegacy({
base,
...config
}).proxy

default:
throw new Error(`Unsupported proxy type: ${proxyType}!`)
}
}
})()