Merge pull request #87 from koajs/original-url
this.originalUrl && this.request.originalUrl
This commit is contained in:
commit
52307eeb72
5 changed files with 25 additions and 1 deletions
|
@ -117,6 +117,7 @@ app.createContext = function(req, res){
|
||||||
request.ctx = response.ctx = context;
|
request.ctx = response.ctx = context;
|
||||||
context.onerror = context.onerror.bind(context);
|
context.onerror = context.onerror.bind(context);
|
||||||
context.cookies = new Cookies(req, res);
|
context.cookies = new Cookies(req, res);
|
||||||
|
context.originalUrl = request.originalUrl = req.url;
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,6 @@ module.exports = {
|
||||||
* Delegate to Request#method.
|
* Delegate to Request#method.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
get method() {
|
get method() {
|
||||||
return this.request.method;
|
return this.request.method;
|
||||||
},
|
},
|
||||||
|
|
|
@ -18,4 +18,12 @@ describe('ctx.path=', function(){
|
||||||
ctx.path.should.equal('/logout');
|
ctx.path.should.equal('/logout');
|
||||||
ctx.url.should.equal('/logout?next=/dashboard');
|
ctx.url.should.equal('/logout?next=/dashboard');
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should change .url but not .originalUrl', function(){
|
||||||
|
var ctx = context({ url: '/login' });
|
||||||
|
ctx.path = '/logout';
|
||||||
|
ctx.url.should.equal('/logout');
|
||||||
|
ctx.originalUrl.should.equal('/login');
|
||||||
|
ctx.request.originalUrl.should.equal('/login');
|
||||||
|
})
|
||||||
})
|
})
|
|
@ -22,4 +22,12 @@ describe('ctx.query=', function(){
|
||||||
ctx.url.should.equal('/store/shoes?page=2&color=blue');
|
ctx.url.should.equal('/store/shoes?page=2&color=blue');
|
||||||
ctx.querystring.should.equal('page=2&color=blue');
|
ctx.querystring.should.equal('page=2&color=blue');
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should change .url but not .originalUrl', function(){
|
||||||
|
var ctx = context({ url: '/store/shoes' });
|
||||||
|
ctx.query = { page: 2 };
|
||||||
|
ctx.url.should.equal('/store/shoes?page=2');
|
||||||
|
ctx.originalUrl.should.equal('/store/shoes');
|
||||||
|
ctx.request.originalUrl.should.equal('/store/shoes');
|
||||||
|
})
|
||||||
})
|
})
|
|
@ -8,4 +8,12 @@ describe('ctx.querystring=', function(){
|
||||||
ctx.url.should.equal('/store/shoes?page=2&color=blue');
|
ctx.url.should.equal('/store/shoes?page=2&color=blue');
|
||||||
ctx.querystring.should.equal('page=2&color=blue');
|
ctx.querystring.should.equal('page=2&color=blue');
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should change .url but not .originalUrl', function(){
|
||||||
|
var ctx = context({ url: '/store/shoes' });
|
||||||
|
ctx.querystring = 'page=2&color=blue';
|
||||||
|
ctx.url.should.equal('/store/shoes?page=2&color=blue');
|
||||||
|
ctx.originalUrl.should.equal('/store/shoes');
|
||||||
|
ctx.request.originalUrl.should.equal('/store/shoes');
|
||||||
|
})
|
||||||
})
|
})
|
Loading…
Reference in a new issue