this.originalUrl && this.request.originalUrl

This commit is contained in:
Jonathan Ong 2013-11-14 14:18:05 -08:00
parent d23ad1a024
commit 18c2cd1dac
5 changed files with 25 additions and 1 deletions

View file

@ -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;
} }

View file

@ -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;
}, },

View file

@ -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');
})
}) })

View file

@ -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');
})
}) })

View file

@ -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');
})
}) })