Skip to content

Commit 665302c

Browse files
committed
adding proxy factory
1 parent 7f3f52c commit 665302c

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

index.js

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable no-useless-call */
22

3-
const fastProxy = require('fast-proxy')
3+
const proxyFactory = require('./lib/proxy-factory')
44
const restana = require('restana')
55
const defaultProxyHandler = (req, res, url, proxy, proxyOpts) => proxy(req, res, url, proxyOpts)
66
const DEFAULT_METHODS = require('restana/libs/methods').filter(method => method !== 'all')
@@ -56,21 +56,7 @@ const gateway = (opts) => {
5656
route.pathRegex = undefined === route.pathRegex ? opts.pathRegex : String(route.pathRegex)
5757

5858
// instantiate route proxy
59-
let proxy
60-
if (proxyType === 'http') {
61-
proxy = fastProxy({
62-
base: opts.targetOverride || route.target,
63-
http2: !!route.http2,
64-
...(opts.fastProxy)
65-
}).proxy
66-
} else if (proxyType === 'lambda') {
67-
proxy = require('http-lambda-proxy')({
68-
target: opts.targetOverride || route.target,
69-
...(route.lambdaProxy || {
70-
region: 'eu-central-1'
71-
})
72-
})
73-
}
59+
const proxy = proxyFactory({ opts, route, proxyType })
7460

7561
// route proxy handler function
7662
const proxyHandler = route.proxyHandler || defaultProxyHandler

lib/proxy-factory.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
'use strict'
2+
const fastProxy = require('fast-proxy')
23

34
module.exports = ({ proxyType, opts, route }) => {
5+
let proxy
6+
if (proxyType === 'http') {
7+
proxy = fastProxy({
8+
base: opts.targetOverride || route.target,
9+
http2: !!route.http2,
10+
...(opts.fastProxy)
11+
}).proxy
12+
} else if (proxyType === 'lambda') {
13+
proxy = require('http-lambda-proxy')({
14+
target: opts.targetOverride || route.target,
15+
...(route.lambdaProxy || {
16+
region: 'eu-central-1'
17+
})
18+
})
19+
}
420

21+
return proxy
522
}

0 commit comments

Comments
 (0)