Fixed redirect helpers due to Request change
Before adoption: this commit came in with the history the project adopted, so no landing records it.
back / home vars can not be global
authored by visionmedia · committed by visionmedia · parent 3a90a78 · Browse files · 3 files·+35 added−29 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+35 added−29 removed
- tests:+7 added−7 removed
- other:+28 added−22 removed
Provenance
- Commit
995cde7- Tree
ef553b5- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent
3a90a78
3 files changed+35 added−29 removed
modified:lib/express/plugins/redirect.js+28 added-22 removed
123456789101112131415161718192021452324252667891011121314151617181920212223242526272829303132333435363710 unmodified lines
// Express - Redirect - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
/** * Redirect to _uri_. * * When using redirect(home) the resolution * is as follows: * * - set('home') * - set('basepath') * - '/' * * When using redirect(back) the HTTP referrer * header is used. Commonly misspelled as 'referer' * which is supported as well. * * @param {string} uri * @settings 'home', 'basepath' * @api public */// --- Request
exports.redirect = function(uri) { header('location', uri) halt(302)}Request.include({ /** * Redirect to _uri_. * * When using redirect('home') the resolution * is as follows: * * - set('home') * - set('basepath') * - '/' * * When using redirect('back') the HTTP referrer * header is used. Commonly misspelled as 'referer' * which is supported as well. * * @param {string} uri * @settings 'home', 'basepath' * @api public */
redirect: function(uri) { if (uri == 'back' || uri == 'home') uri = this[uri] this.header('location', uri) this.halt(302) } })
// --- Expose
process.mixin(GLOBAL, exports)
10 unmodified linesmodified:spec/spec.plugins.common-logger.js+1 added-1 removed
10 unmodified lines111213141515161718194 unmodified lines10 unmodified lines it 'should output in common log format' GLOBAL.stub('puts') GLOBAL.should.receive('puts') get('/style.css', function(){ contentType('css') this.contentType('css') return 'body { background: #000; }' }) get('/style.css') end4 unmodified linesmodified:spec/spec.plugins.redirect.js+6 added-6 removed
14 unmodified lines15161718191920212222232425262728293030313233342 unmodified lines3738394041414243444546474849495051525354555656575859602 unmodified lines14 unmodified lines get('/logout').headers['location'].should.eql '/' end end describe 'redirect(back)' describe 'redirect("back")' it 'should check Referrer header' get('/logout', function(){ redirect(back) this.redirect('back') }) var response = get('/logout', { headers: { referrer: '/login' }}) response.headers['location'].should.eql '/login' end it 'should check referer header' get('/logout', function(){ redirect(back) this.redirect('back') }) var response = get('/logout', { headers: { referer: '/login' }}) response.headers['location'].should.eql '/login' end2 unmodified lines describe 'redirect(home)' it 'should check set("home")' set('home', '/login') get('/logout', function(){ redirect(home) this.redirect('home') }) get('/logout').headers['location'].should.eql '/login' end it 'should check set("basepath")' set('basepath', '/web/') get('/logout', function(){ redirect(home) this.redirect('home') }) get('/logout').headers['location'].should.eql '/web/' end it 'should default to "/"' get('/logout', function(){ redirect(home) this.redirect('home') }) get('/logout').headers['location'].should.eql '/' end end2 unmodified lines