From ead213a5063ee9126bd5957a09836be873f107cd Mon Sep 17 00:00:00 2001 From: David Phillips Date: Sat, 2 Nov 2019 13:57:39 -0400 Subject: [PATCH] responder now checks routes added via `add_route` before mounted routes routes added by `add_route` (including @api.route()) are now checked before routes that were added by api.mount() this especially helps cases for situations where the static route defined by the API class is '/' but the default route is '/' as well --- responder/routes.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/responder/routes.py b/responder/routes.py index 6ff6535..6e6de67 100644 --- a/responder/routes.py +++ b/responder/routes.py @@ -302,6 +302,15 @@ class Router: path = scope["path"] root_path = scope.get("root_path", "") + # Check "primary" mounted routes first (before submounted apps) + route = self._resolve_route(scope) + + scope["before_requests"] = self.before_requests + + if route is not None: + await route(scope, receive, send) + return + # Call into a submounted app, if one exists. for path_prefix, app in self.apps.items(): if path.startswith(path_prefix): @@ -315,12 +324,4 @@ class Router: await app(scope, receive, send) return - route = self._resolve_route(scope) - - scope["before_requests"] = self.before_requests - - if route is not None: - await route(scope, receive, send) - return - await self.default_response(scope, receive, send)