Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should redirects be absolute? #45

Open
peey opened this issue May 8, 2016 · 3 comments
Open

Should redirects be absolute? #45

peey opened this issue May 8, 2016 · 3 comments
Labels

Comments

@peey
Copy link

peey commented May 8, 2016

Since this.url is relative, I do not think that redirects should be absolute.

though currently they are. For example, if you do

website.use(function *() {
   if (this.url == "/proper")  {
       this.body = "Rejoice";
   } else {
       this.redirect("/proper");
   }
})

app.use(mount('/website', website))

Then navigating to example.com/website/not-proper redirects to example.com/proper and not example.com/website/proper

@haoxins
Copy link
Member

haoxins commented May 16, 2016

.redirect is Koa's logic, not koa-mount!
Maybe it's reasonable to add mountPath prefix in .redirect().

BTW, you can use relative path this.redirect("proper"), it's permitted in rfc7231

@peey
Copy link
Author

peey commented May 16, 2016

I too think it's reasonable, because koa-mount makes it possible to code the sub-application without worrying about which parent path it will be mounted on

from README.md

The path passed to mount() is stripped from the URL temporarily until the stack unwinds. This is useful for creating entire apps or middleware that will function correctly regardless of which path segment(s) they should operate on.

Though you are correct that this.redirect("proper") may work, but it won't be optimal if the url you are trying to redirect has a slash character in it. But I guess that will be uncommon.

Still it would be nice if there were a way to define relative urls from the mounted path for redirection just like you get on path that is passed to middleware.

@haoxins
Copy link
Member

haoxins commented May 16, 2016

@peey Just submit a PR to koa koajs/koa#733

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants