Skip to content

[#256] Adds test to document operating on query params. #478

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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