Skip to content

Commit 8b716ca

Browse files
authored
[#374] fixes bug in filter signature (#389)
1 parent ea936f3 commit 8b716ca

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

README.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,11 @@ DEPRECATED. See proxyReqPathResolver
122122

123123
DEPRECATED. See proxyReqPathResolver
124124

125-
#### filter
125+
#### filter (supports Promises)
126126

127-
The ```filter``` option can be used to limit what requests are proxied. Return ```true``` to execute proxy.
127+
The ```filter``` option can be used to limit what requests are proxied. Return
128+
```true``` to continue to execute proxy; return false-y to skip proxy for this
129+
request.
128130

129131
For example, if you only want to proxy get request:
130132

@@ -136,6 +138,22 @@ app.use('/proxy', proxy('www.google.com', {
136138
}));
137139
```
138140

141+
Promise form:
142+
143+
```js
144+
app.use(proxy('localhost:12346', {
145+
filter: function (req, res) {
146+
return new Promise(function (resolve) {
147+
resolve(req.method === 'GET');
148+
});
149+
}
150+
}));
151+
```
152+
153+
Note that in the previous example, `resolve(false)` will execute the happy path
154+
for filter here (skipping the rest of the proxy, and calling `next()`).
155+
`reject()` will also skip the rest of proxy and call `next()`.
156+
139157
#### userResDecorator (was: intercept) (supports Promise)
140158

141159
You can modify the proxy's response before sending it to the client.

app/steps/filterUserRequest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function filterUserRequest(container) {
1010
var resolverFn = container.options.filter || defaultFilter;
1111

1212
return Promise
13-
.resolve(resolverFn(container.proxy.reqBuilder, container.user.req))
13+
.resolve(resolverFn(container.user.req, container.user.res))
1414
.then(function (shouldIContinue) {
1515
if (shouldIContinue) {
1616
return Promise.resolve(container);

0 commit comments

Comments
 (0)