Skip to content

Commit

Permalink
[#256] Adds test to document operating on query params.
Browse files Browse the repository at this point in the history
  • Loading branch information
nik-blue-lava committed Jan 13, 2021
1 parent 2aec188 commit fa729c8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
24 changes: 24 additions & 0 deletions test/resolveProxyReqPath.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [{
Expand Down
4 changes: 4 additions & 0 deletions test/support/proxyTarget.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit fa729c8

Please sign in to comment.