Skip to content

Commit 73b295c

Browse files
committed
[#256] Adds test to document operating on query params.
1 parent 2aec188 commit 73b295c

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

test/resolveProxyReqPath.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,29 @@ describe('resolveProxyReqPath', function () {
8282
});
8383

8484
describe('testing example code in docs', function () {
85+
it('allows modification of get params', function (done) {
86+
var proxyTarget = require('../test/support/proxyTarget');
87+
var proxyServer = proxyTarget(12345, 100);
88+
89+
var app = express();
90+
app.use(proxy('localhost:12345', {
91+
proxyReqPathResolver: function (req) {
92+
var parts = req.url.split('?');
93+
var queryString = 'newaddedparam=abcde';
94+
var updatedPath = parts[0].replace(/test/, 'tent');
95+
return updatedPath + (queryString ? '?' + queryString : '');
96+
}
97+
}));
98+
99+
request(app)
100+
.get('/returnRequestParams')
101+
.end(function (err, res) {
102+
if (err) { return done(err); }
103+
assert(res.body.newaddedparam == 'abcde', 'author can add query params');
104+
done();
105+
});
106+
});
107+
85108
it('works as advertised', function (done) {
86109
var proxyTarget = require('../test/support/proxyTarget');
87110
var proxyRouteFn = [{

test/support/proxyTarget.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ function proxyTarget(port, timeout, handlers) {
4040
res.json({ headers: req.headers });
4141
});
4242

43+
target.use('/returnRequestParams', function(req, res) {
44+
res.json(req.query);
45+
});
46+
4347
target.use(function(err, req, res, next) {
4448
res.send(err);
4549
next();

0 commit comments

Comments
 (0)