forked from nsimmons/koa-better-http-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
31 lines (26 loc) · 879 Bytes
/
index.js
File metadata and controls
31 lines (26 loc) · 879 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"use strict";
var ScopeContainer = require("./lib/scopeContainer");
var assert = require("assert");
var executeWithRetry = require("./app/steps/executeWithRetry");
module.exports = function proxy(host, userOptions) {
assert(host, "Host should not be empty");
return function (ctx, next) {
var container = new ScopeContainer(ctx, host, userOptions);
// Skip proxy if filter is falsey. Loose equality so filters can return
// false, null, undefined, etc.
if (!container.options.filter(ctx)) {
if (next) {
return Promise.resolve(null).then(next);
} else {
return Promise.resolve(null);
}
}
var proxyPromise = executeWithRetry(container);
// Follow Koa native pattern: only call next() if it's provided
if (next) {
return proxyPromise.then(next);
} else {
return proxyPromise;
}
};
};