|
1 | 1 | 'use strict' |
2 | 2 |
|
3 | | -const fastProxy = require('fast-proxy-lite') |
| 3 | +module.exports = (() => { |
| 4 | + let fastProxyLite, httpLambdaProxy, fastProxyLegacy |
4 | 5 |
|
5 | | -module.exports = ({ proxyType, opts, route }) => { |
6 | | - let proxy |
| 6 | + return ({ proxyType, opts, route }) => { |
| 7 | + const base = opts.targetOverride || route.target |
| 8 | + const config = route.proxyConfig || {} |
7 | 9 |
|
8 | | - if (proxyType === 'http') { |
9 | | - proxy = fastProxy({ |
10 | | - base: opts.targetOverride || route.target, |
11 | | - ...route.proxyConfig |
12 | | - }).proxy |
13 | | - } else if (proxyType === 'lambda') { |
14 | | - proxy = require('http-lambda-proxy')({ |
15 | | - target: opts.targetOverride || route.target, |
16 | | - region: 'eu-central-1', |
17 | | - ...route.proxyConfig |
18 | | - }) |
19 | | - } else if (proxyType === 'http-legacy') { |
20 | | - proxy = require('fast-proxy')({ |
21 | | - base: opts.targetOverride || route.target, |
22 | | - ...route.proxyConfig |
23 | | - }).proxy |
24 | | - } else { |
25 | | - throw new Error(`Unsupported proxy type: ${proxyType}!`) |
26 | | - } |
| 10 | + switch (proxyType) { |
| 11 | + case 'http': |
| 12 | + fastProxyLite = fastProxyLite || require('fast-proxy-lite') |
| 13 | + return fastProxyLite({ |
| 14 | + base, |
| 15 | + ...config |
| 16 | + }).proxy |
| 17 | + |
| 18 | + case 'lambda': |
| 19 | + httpLambdaProxy = httpLambdaProxy || require('http-lambda-proxy') |
| 20 | + return httpLambdaProxy({ |
| 21 | + target: base, |
| 22 | + region: 'eu-central-1', |
| 23 | + ...config |
| 24 | + }) |
27 | 25 |
|
28 | | - return proxy |
29 | | -} |
| 26 | + case 'http-legacy': |
| 27 | + fastProxyLegacy = fastProxyLegacy || require('fast-proxy') |
| 28 | + return fastProxyLegacy({ |
| 29 | + base, |
| 30 | + ...config |
| 31 | + }).proxy |
| 32 | + |
| 33 | + default: |
| 34 | + throw new Error(`Unsupported proxy type: ${proxyType}!`) |
| 35 | + } |
| 36 | + } |
| 37 | +})() |
0 commit comments