-
Notifications
You must be signed in to change notification settings - Fork 368
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
Make trailing slash optional in splat params. #87
Comments
You could do |
I know there are ways to achieve this currently I just think the default isn't as useful as it could be. I was also kind of surprised that '/test/(.*)?' Works perfectly but '/test/*?' Does not. |
It's documented in the README, and this is the reason I had disabled the |
I'm going to close this since the behaviour is set and won't be changing. Even if it did change, there's no guarantee that instead most people really want the current functionality and you're just an outlier. I think the current behaviour is expected, the asterisk is not a param group - it's just an asterisk, but I will keep a look out for similar comments. |
Ok, so revisiting this from #92 (comment). If this change were to happen, it'd be kind of defeating the purpose I added it back to begin with (which was legacy Express.js support). Mostly likely, it'd be compatible with how most people use it - except for that small percent that may care about the prefix (for example, this module may be used in a different router that doesn't normalise requests like Edit: Deleted content relating to how they match (E.g. |
Heres my thinking - Say you have a path Ultimately for me the Although I think that this is the way it should work I totally understand where your coming from. It'd be nice to have others chime in but I personally don't think this change would effect many people. Also if you are curious as to why I need this feature and created a wrapper, it is because I am using it here to facilitate mounting routers at paths. To me it makes sense to do it this way because you are explicitly saying at If you come to a conclusion on this please ping me. |
Thanks for the link @DylanPiercey, that actually helps a lot. I don't have any conclusion still, but it looks like you aren't using One big reason for mounting is to automatically strip the prefix. Does that library do this for you? Also, it looks like I should add some test-cases of the hostname routing 😄 |
Thanks for looking through the code. I am actually using Currently mounting in Rill doesn't update any existing path's/pathname's because I found that to be pretty invasive and haven't really needed it, however I just released a patch that exposes Could you elaborate on what test-cases I should add for hostname? That'd be extremely helpful. Also, if your not super busy do you think you'd have a few minutes to discuss this further over irc, gitter or something? If not thats cool. |
Sorry, not you for the test-cases, me 😄 If you're using I can chat anytime, let me know where is easiest. On stripping the prefix, it's actually extremely handy and something I regularly rely on, so you may want to consider support it. The big advantage of stripping it as you go down the stack is that you can mount third-party projects into yours without any code changes required. However, this might be less of an issue because you're doing something to cause the paths to keep matching as they go down anyway. But doing this ensures anyone using it, not just the router, can use it in any context easily. It's pretty cool to re-use someone else's router into yours (E.g. Kue comes to mind). |
Ah okay, thought you were saying some tests were missing from Rill 😜. I agree that mounting and faking that a nested app is at the top level is useful however in my experience i have found the big advantage comes from just the routing aspect of this and it's a bit of a leaky abstraction. It's even more difficult when you have phases to your routing which Koa and Rill do. If you look at koa-compose you can see how it has to juggle the path name back and forth which IMO is a little dirty, not to mention that it re-parses the path in koa for each of these switches. Also things like redirects just go completely wonky unless you patch them as well. Because of that I just opted to storing a variable on the request which is the current Thanks for taking the time to think about this further, much appreciated. |
Interesting, thanks for the links. I've built middleware with mounting in the past, and although it's not perfect it's not bad to add two lines before and after to strip and re-add it. The re-parsing is unfortunate, my first thought is that it could be improved though by making the The redirect issue is a good point too, but redirects can be relative so working around that is simple - just send relative paths instead of absolute and continue allowing absolute for the use-case it exists for. For DX, it might be worth adding two methods so people can avoid running into a case they didn't want. I don't think implicitly adding the mount path here is a good behaviour either, since it's very likely people want an absolute path in some cases - but I do agree it's a leak in terms of typical thinking, so you'd need to shape user expectations through the API instead. On a side note, is that what we're calling that pattern - "phases"? I've been using it for HTTP requests also - see http://github.com/blakeembrey/throwback and https://github.com/blakeembrey/popsicle. |
Yeah mounting has always been a tough one for me, although i'm pretty happy with the Rill router at the moment. I borrowed the term Also popsicle looks sweet, thanks for the link! Universal javascript libraries always make me happy. If you have any more questions for me about how I am using |
@blakeembrey - Ping me if this gets added or if it needs more discussion, appreciate you looking into it again. |
Absolutely, no worries. I was considering if I should just make standalone behaviours of |
I think Ideally all of these would be equivalent except without specifying names for the capture groups. 'make:part+.com'
'make.+.com'
'make:part*.com'
'make.*.com'
'make:part?.com'
'make.?.com' To me that's how I intuitively think it should work, this way '*', '+', and '?' have the same functionality no matter where it is. |
Ok, I'm semi-onboard. If it acts the same, you lose the behaviour around "wildcard" matching everything like Edit: I feel like you would, since you're doing sub-routing. If it wasn't matched, things in the sub-route might be skipped that would otherwise be valid. |
I personally wouldn't have expected I personally think it should be on the developer to properly format the url to |
Ping @blakeembrey. Do you think it's worth reopening this issue an/or perhaps getting some outside input somehow? |
Sure. Let me know how you'd like to get that 😄 |
Let me know if this is still an issue. I'm dropping Edit: And I've lost a lot of context on the next action item for this issue. |
Thanks for the update. Going to dig into this new version now! |
Let me know if anything is missing 😄 I think it was mostly your use-case ideas that ended up with the new options. |
@blakeembrey nearly the same issue over in URLPattern: whatwg/urlpattern#163 |
Hey,
I often find myself writing paths like this:
However 100% of the time what I actually want is this:
Is it possible to make a splat only section of the path allow for optional trailing slash?
I realize this would be a breaking change, but I can't perceive any crazy issues with it and it would be pretty convenient for myself and perhaps others.
The text was updated successfully, but these errors were encountered: