Skip to content

Commit

Permalink
Reflect CONFIG.root_path in get_base_url
Browse files Browse the repository at this point in the history
  • Loading branch information
markus1978 committed Jan 6, 2021
1 parent 634a2c2 commit c1837bd
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions optimade/server/routers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
)


Expand All @@ -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)

Expand Down

0 comments on commit c1837bd

Please sign in to comment.