Skip to content
Myr

Added dynamic redirect mapping

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent b75246e · Browse files · 2 files+42 added−8 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+42 added−8 removed

  • tests:+13 added−0 removed
  • other:+29 added−8 removed

2 files+42 added−8 removed

modified:lib/express/response.js+29 added-8 removed
modified:test/response.test.js+13 added
98 unmodified lines
99 app2.set('home', '/blog');100101 app2.redirect('google', 'http://google.com');102103 app2.redirect('blog', function(req, res, params){104 return params.id105 ? '/user/' + params.id + '/blog'106 : null;107 });108 109 app.get('/', function(req, res){110 res.redirect('http://google.com', 301);111 });112
19 unmodified lines
132 133 app2.get('/google', function(req, res){134 res.redirect('google');135 });136137 app2.get('/user/:id', function(req, res){138 res.redirect('blog');139 });140 141 assert.response(app,142 { url: '/' },143 { body: '', status: 301, headers: { Location: 'http://google.com' }});
21 unmodified lines
165 { body: '', status: 302, headers: { Location: '/blog' }});166 assert.response(app2,167 { url: '/google' },168 { body: '', headers: { Location: 'http://google.com' }});169 assert.response(app2,170 { url: '/user/12' },171 { body: '', headers: { Location: '/user/12/blog' }});172 173 }174};