Skip to content

Commit

Permalink
[#374] fixes bug in filter signature (#389)
Browse files Browse the repository at this point in the history
  • Loading branch information
monkpow committed Oct 31, 2018
1 parent ea936f3 commit 8b716ca
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
22 changes: 20 additions & 2 deletions README.md
Expand Up @@ -122,9 +122,11 @@ DEPRECATED. See proxyReqPathResolver

DEPRECATED. See proxyReqPathResolver

#### filter
#### filter (supports Promises)

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

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

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

Promise form:

```js
app.use(proxy('localhost:12346', {
filter: function (req, res) {
return new Promise(function (resolve) {
resolve(req.method === 'GET');
});
}
}));
```

Note that in the previous example, `resolve(false)` will execute the happy path
for filter here (skipping the rest of the proxy, and calling `next()`).
`reject()` will also skip the rest of proxy and call `next()`.

#### userResDecorator (was: intercept) (supports Promise)

You can modify the proxy's response before sending it to the client.
Expand Down
2 changes: 1 addition & 1 deletion app/steps/filterUserRequest.js
Expand Up @@ -10,7 +10,7 @@ function filterUserRequest(container) {
var resolverFn = container.options.filter || defaultFilter;

return Promise
.resolve(resolverFn(container.proxy.reqBuilder, container.user.req))
.resolve(resolverFn(container.user.req, container.user.res))
.then(function (shouldIContinue) {
if (shouldIContinue) {
return Promise.resolve(container);
Expand Down

0 comments on commit 8b716ca

Please sign in to comment.