question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow insertion of routes with higher priority than existing ones.

See original GitHub issue

Is your feature related to a problem? Please describe.

It would be helpful to have a clean way to insert new routes and mounts at the front of the route list. Specifically, if one has a Starlette app created by a library and that app includes a catch-all route (i.e. "/{path:path}") then currently it is impossible to add any more specific routes without delving into the internals of the router (e.g. app.routes.insert(0, new_route) ).

An example of a situation where this is a problem is when trying to add additional routes to an application created with JustPy. JustPy creates its Starlette app, complete with a catch-all route, when the library is imported, making it impossible to add an API for the app without direct manipulation of the route table.

Describe the solution you would like.

Ideally Router.add_route() and Router.mount() (and possibly their corresponding reflections in the Starlette class) should have a flag, defaulting to False, to indicate that the route should be added with highest priority instead of lowest priority.

Describe alternatives you considered

One alternative to expanding the API would be to explicitly document that direct manipulation of the list value in the Starlette.routes property is allowed. Doing this currently works, but it depends on the current implementation of the routing system and will break if that design were to change significantly. Adding the flag to the mount() and add_route() methods would allow for changes under the hood without breaking code.

Additional context

My use case is specifically to do with trying to add additional routes to an application built with JustPy, but there are likely other libraries that behave in similar ways.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Kludexcommented, Jun 8, 2021

Having said all that, is there a strong case for not providing more flexible insertion of routes into Starlette?

Well, I guess it’s more about not adding unnecessary complexity.

Also, as you said, it’s a bug on JustPy that is in our path here. I guess your initial solution (app.routes.insert(0, new_route)) should take place here. 🤔

I’m closing this issue, but we’re open to reconsideration if someone makes a compelling case.

0reactions
Kludexcommented, Sep 9, 2022

There’s still no compelling case to reconsider the previous decision.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Order of routes | Cloud VPN
For both dynamic and static routing, if more than one custom route exists for the same destination and has the same priority and...
Read more >
Site-to-Site VPN routing options - AWS Documentation
If propagated routes from a Site-to-Site VPN connection or AWS Direct Connect connection have the same destination CIDR block as other existing static...
Read more >
Set Up Secondary Routing Priority - Salesforce Help
Let your agents tackle the right cases first with secondary routing priority. Required User Permissions User Permissions Needed To set up Omni-Channel: Cu....
Read more >
Is it possible in IOS to have two static routes for the same ...
Is it possible in IOS to have two static routes for the same subnet, one a higher priority and "failover" between the 2?...
Read more >
Static Route Preferences and Qualified Next Hops | Junos OS
A static route destination address can have multiple next hops associated with it. In this case, multiple routes are inserted into the routing...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found