redirect to root url from a mounted endpoint?

1,222 views
Skip to first unread message

Paul Vencill

unread,
Dec 6, 2011, 12:14:54 PM12/6/11
to expre...@googlegroups.com
Express docs, say that the res.redirect() method 'respects mount points', so if I'm in an app mounted at /blog and I call res.redirect('/posts'), it'll redirect to /blog/posts.  Is there any way to override that behavior?  Specifically,I'd like my auth module to be able to redirect to /login from anywhere in the app (including inside mounted sub-apps).  

Thanks.

TJ Holowaychuk

unread,
Dec 6, 2011, 12:14:57 PM12/6/11
to expre...@googlegroups.com
I was just thinking about this the other day for express 3x actually. I'm starting to think it's too high-level of a concept for Express, to override it you would have to pass an absolute url. perhaps maybe a solution would be:

res.redirect('/login')   absolute to GET /login

res.redirect('login')    relative to GET /blog/login

-- 
TJ Holowaychuk

On Tuesday, December 6, 2011 at 9:14 AM, Paul Vencill wrote:

Express docs, say that the res.redirect() method 'respects mount points', so if I'm in an app mounted at /blog and I call res.redirect('/posts'), it'll redirect to /blog/posts.  Is there any way to override that behavior?  Specifically,I'd like my auth module to be able to redirect to /login from anywhere in the app (including inside mounted sub-apps).  

Thanks.

--
You received this message because you are subscribed to the Google Groups "Express" group.
To post to this group, send email to expre...@googlegroups.com.
To unsubscribe from this group, send email to express-js+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/express-js?hl=en.

Paul Vencill

unread,
Dec 6, 2011, 1:04:37 PM12/6/11
to expre...@googlegroups.com
yeah, that'd be good & close to how most folks do it (except for the ~/ convention for root that certain frameworks use).  I'll hack my absolute url until then, but thanks.

Paul

Ryan Schmidt

unread,
Dec 7, 2011, 2:29:23 AM12/7/11
to expre...@googlegroups.com

On Dec 6, 2011, at 11:14, Paul Vencill wrote:

> Express docs, say that the res.redirect() method 'respects mount points', so if I'm in an app mounted at /blog and I call res.redirect('/posts'), it'll redirect to /blog/posts. Is there any way to override that behavior? Specifically,I'd like my auth module to be able to redirect to /login from anywhere in the app (including inside mounted sub-apps).

Yeah. I wrote rather a lot of odd code to deal with this problem, so you're not alone. I don't think I should share what I did, since I'm not at all sure it's the best way to do it (it feels convoluted), but I'll be interested in the other responses.


vision media [ Tj Holowaychuk ]

unread,
Dec 7, 2011, 11:25:32 AM12/7/11
to expre...@googlegroups.com
In 3x you can now do:

   res.redirect('/relative/to/host');
   res.redirect('relative/to/mount-point');
   res.redirect('./relative/to/pathname');

--
You received this message because you are subscribed to the Google Groups "Express" group.
To post to this group, send email to expre...@googlegroups.com.
To unsubscribe from this group, send email to express-js+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/express-js?hl=en.




--
Tj Holowaychuk
Vision Media
President & Creative Lead

vision media [ Tj Holowaychuk ]

unread,
Dec 7, 2011, 11:25:55 AM12/7/11
to expre...@googlegroups.com
oh and stuff like:
   res.redirect('../new');

Paul Vencill

unread,
Dec 7, 2011, 1:15:11 PM12/7/11
to expre...@googlegroups.com
Very cool
Reply all
Reply to author
Forward
0 new messages