Skip to content

Commit

Permalink
[fixed] fixed crash when matching params
Browse files Browse the repository at this point in the history
  • Loading branch information
jergason committed Dec 10, 2014
1 parent 60f37bc commit bbe67b3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function pixie(options) {

// if we have dynamic segments in the url
if (shouldReplacePathParams) {
requestOpts.url = option.host + replacePathParams(path, this.params);
requestOpts.url = options.host + replacePathParams(path, this.params);
}

// something possibly went wrong if they have no body but are sending a
Expand Down
31 changes: 31 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,19 @@ function makeTestServer() {

app.use(body());
app.use(router(app));

app.get('/hurp', function* (){
this.body = {hurp: 'durp'}
});

app.get('/i500', function* (){
this.status = 500;
});

app.get('/haveparams/:foo', function*() {
this.body = {foo: this.params.foo};
});

app.post('/hurp', function* () {
this.set('x-some-dumb-header', 'Im-set-yo');
this.body = this.request.body;
Expand Down Expand Up @@ -128,4 +135,28 @@ describe('pixie-proxy', function() {
});
});
});

it('replaces path params with their this.params', function(done) {
var testServer = makeTestServer();
var PORT = getRandomPort();
testServer.listen(PORT, function() {

var app = koa();
app.use(body());
app.use(router(app));

var proxy = pixie({host: 'http://localhost:' + PORT});

app.get('/haveparams/:hurp', proxy('/haveparams/:hurp'));
supertest(http.createServer(app.callback()))
.get('/haveparams/bar')
.expect(200)
.end(function(err, res) {
assert.ifError(err);
assert.deepEqual(res.body, {foo: 'bar'});
testServer.close();
done();
});
});
});
});

0 comments on commit bbe67b3

Please sign in to comment.