-
Notifications
You must be signed in to change notification settings - Fork 82
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
Allow overlapping route definitions #199
Comments
Off the top of my head, I think the reasons we chose to disallow this early on were (1) we hoped this would encourage clearer code structure. I'd find it annoying to have to track down which handler was going to be run for a request by mentally evaluating the routing table's rules. and (2) it's easy to do this accidentally and be very confused by the behavior. I burned a bunch of time with Actix debugging why a different handler was being run than what I intended. |
I'd suggest that this is an area where Dropshot may be opinionated: I view the absence of this as a feature of Dropshot. |
That's fine with me as long as we have a nice way of solving the proximate issue (oxidecomputer/omicron#430), which is distinguishing console routes and API routes in Nexus, ideally without having an ugly contrived prefix like We can probably just stick with a slight modification of what we're already doing: use Right now the API routes don't actually start with |
Respectfully, I'd like to disagree. For example, having a catch-all |
I agree with ahl′ -- I would in some places use a catch-all route myself, with the knowledge that it is on my own recognisance. |
I think it's more of a footgun than it looks because adding any route in the catch-all space is a potentially breaking change, and you'd have no way to know. As a concrete example, suppose we went down this path to solve oxidecomputer/omicron#430, so that Agreed on the 404 page use case, but I wonder if there are safer ways to provide that (see #39/#40)? |
We now allow overlapping routes based on specificity ** This is similar to https://go.dev/blog/routing-enhancements)[Go's new routing enhancements]. (And it intuitively makes sense). ** https://github.com/oxidecomputer/dropshot/issues/199[Oxide discussion on route overlapping here]. ** The motivation is because I usually keep things in a single binary and it just looks better for my frontend to be accessed at `https://myapp.com/` and my api to be accessed at `https://myapp.com/api`. Due to the overlapping restriction the frontend previously had to be at something like `https://myapp.com/-/`. Some say this is bad URL design but the tribe has spoken. ** There are two drawbacks to this approach: *** If you make overlapping routes mistakenly, you might be routed to a handler that you did not expect. The only way you find this out is through thorough testing. *** Currently because of how specificity matching works we don't do backmatching. That means that if we have two routes registered: `/foo/bar` and `/{slug}/bar/lol`, A request intended for path `/foo/bar/lol` will fail with a 404.
So it's been two years and I would still really like to have this functionality. Would it be alright to add something like this if we can have it be off by default, thus requiring people to opt in? |
In offline discussion I think we decided:
|
For the console routes, the lack of overlapping routes is clearly not a big deal. Every once in a while we have to add a new top-level path here. That's it. |
I have found the lack of this annoying, because I can't do the rails-like URLs of |
Whether we need this depends on some other architectural decisions. I'm writing this up so I can refer to it elsewhere.
Right now, defining both
GET /abc/*
andGET /abc/def
is an error at startup because the route definitions overlap, and Dropshot would not know which to handler to call when a request matches both routes. There are a couple of ways we could break ties:BTreeMap
for the route nodes, so we know the insertion order) and to understand/abc/def
goes to the exact match because it ranks higher than a wildcard matchThe text was updated successfully, but these errors were encountered: