diff --git a/test/resolveProxyReqPath.js b/test/resolveProxyReqPath.js index d02c80c1..8dbda1c1 100644 --- a/test/resolveProxyReqPath.js +++ b/test/resolveProxyReqPath.js @@ -82,6 +82,30 @@ describe('resolveProxyReqPath', function () { }); describe('testing example code in docs', function () { + it('allows modification of get params', function (done) { + var proxyTarget = require('../test/support/proxyTarget'); + var proxyServer = proxyTarget(12346, 100); + + var app = express(); + app.use(proxy('localhost:12346', { + proxyReqPathResolver: function (req) { + var parts = req.url.split('?'); + var queryString = 'newaddedparam=abcde'; + var updatedPath = parts[0].replace(/test/, 'tent'); + return updatedPath + (queryString ? '?' + queryString : ''); + } + })); + + request(app) + .get('/returnRequestParams') + .end(function (err, res) { + if (err) { return done(err); } + assert(res.body.newaddedparam === 'abcde', 'author can add query params');A + proxyServer.close(); + done(); + }); + }); + it('works as advertised', function (done) { var proxyTarget = require('../test/support/proxyTarget'); var proxyRouteFn = [{ diff --git a/test/support/proxyTarget.js b/test/support/proxyTarget.js index b6ec0810..1906ddfd 100644 --- a/test/support/proxyTarget.js +++ b/test/support/proxyTarget.js @@ -40,6 +40,10 @@ function proxyTarget(port, timeout, handlers) { res.json({ headers: req.headers }); }); + target.use('/returnRequestParams', function(req, res) { + res.json(req.query); + }); + target.use(function(err, req, res, next) { res.send(err); next();