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

Application-wide route prefix management #11

Open
loppear opened this issue Sep 20, 2016 · 4 comments
Open

Application-wide route prefix management #11

loppear opened this issue Sep 20, 2016 · 4 comments

Comments

@loppear
Copy link
Contributor

loppear commented Sep 20, 2016

Rather than modules all managing a "baseUrl" config and exposing that as a responder for other modules to retrieve and use in constructing sub-urls, provide a general mechanism for prefixing routes. In effect, routes become a namespace with known values (commonly based on module name) (/admin/, /users/), and router handles where those actually respond.

Proposal

Router config gets a routePrefixes key, with possible values like:

"routePrefixes": {
  "/": "/myapp/"
  "/users": "/staff",
  "/admin": "/manage"
}

These are all checked for initial matches to routes on startup when routes are actually registered with express, so this example would produce urls like:

/myapp/
/myapp/staff
/myapp/manage

And router provides helpers (responder and ejs) for finding the real value of a route for redirects or links:

  router.realPath("/admin/whatever").then(::res.redirect)
  <a href="<%= realPath("/users/profile") %>">
@mjreich
Copy link
Contributor

mjreich commented Sep 20, 2016

Would adding router middleware to auto redirect on found mappings handle most cases? I guess there would still be the possibility for collisions.

@mjreich
Copy link
Contributor

mjreich commented Sep 20, 2016

Also, this feels like it could very easily break everything unless everyone opts in.

@loppear
Copy link
Contributor Author

loppear commented Sep 20, 2016

Yes, hard coded routes would be liable to break, everyone would need to use realPath. Just like right now everyone needs to know that they need to construct user/admin paths by pulling some global config.

I don't think redirecting middleware helps the CAIT case where the app itself is mounted somewhere that is shared. Same issue, everyone would be expected to use realPath.

@mjreich
Copy link
Contributor

mjreich commented Sep 20, 2016

Ok, good points. I think this is a fine solution then.

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

No branches or pull requests

2 participants