From c1837bdebfda9703b27bdab261e23c9ed1bc1be8 Mon Sep 17 00:00:00 2001 From: Markus Scheidgen Date: Tue, 5 Jan 2021 15:27:26 +0100 Subject: [PATCH] Reflect CONFIG.root_path in get_base_url --- optimade/server/routers/utils.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/optimade/server/routers/utils.py b/optimade/server/routers/utils.py index 45ecdefcd1..bae1923709 100644 --- a/optimade/server/routers/utils.py +++ b/optimade/server/routers/utils.py @@ -185,10 +185,11 @@ def get_base_url( if isinstance(parsed_url_request, str) else parsed_url_request ) + root_path = CONFIG.root_path.rstrip("/") if CONFIG.root_path else "" return ( CONFIG.base_url.rstrip("/") if CONFIG.base_url - else f"{parsed_url_request.scheme}://{parsed_url_request.netloc}" + else f"{parsed_url_request.scheme}://{parsed_url_request.netloc}{root_path}" ) @@ -213,9 +214,10 @@ def get_entries( query = urllib.parse.parse_qs(request.url.query) query["page_offset"] = int(query.get("page_offset", [0])[0]) + len(results) urlencoded = urllib.parse.urlencode(query, doseq=True) - base_url = get_base_url(request.url) + root_path = CONFIG.root_path.rstrip("/") if CONFIG.root_path else "" + base_url = f"{get_base_url(request.url)}{request.url.path.replace(root_path, '')}" - links = ToplevelLinks(next=f"{base_url}{request.url.path}?{urlencoded}") + links = ToplevelLinks(next=f"{base_url}?{urlencoded}") else: links = ToplevelLinks(next=None)