Skip to content

Commit e413875

Browse files
committed
fix url links with root-path
1 parent 32b3c6d commit e413875

File tree

3 files changed

+6
-12
lines changed

3 files changed

+6
-12
lines changed

stac_fastapi/pgstac/models/links.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def base_url(self):
5151
@property
5252
def url(self):
5353
"""Get the current request url."""
54-
return str(self.request.url)
54+
return urljoin(str(self.request.base_url), str(self.request.url.path).lstrip("/"))
5555

5656
def resolve(self, url):
5757
"""Resolve url to the current request url."""
@@ -143,7 +143,7 @@ def link_next(self) -> Optional[Dict[str, Any]]:
143143
"rel": Relations.next.value,
144144
"type": MimeTypes.geojson.value,
145145
"method": method,
146-
"href": str(self.request.url),
146+
"href": self.url,
147147
"body": {**self.request.postbody, "token": f"next:{self.next}"},
148148
}
149149

@@ -167,7 +167,7 @@ def link_prev(self) -> Optional[Dict[str, Any]]:
167167
"rel": Relations.previous.value,
168168
"type": MimeTypes.geojson.value,
169169
"method": method,
170-
"href": str(self.request.url),
170+
"href": self.url,
171171
"body": {**self.request.postbody, "token": f"prev:{self.prev}"},
172172
}
173173
return None

tests/api/test_links.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ async def collections(request: Request):
6060
base_url="http://stac.io",
6161
root_path=root_path,
6262
) as client:
63-
response = client.get(f"{endpoint_prefix}/search")
63+
response = client.get(f"{prefix}/search")
6464
assert response.status_code == 200
6565
assert response.json()["url"] == url_prefix + "/search"
6666
assert response.json()["base_url"].rstrip("/") == url_prefix
@@ -71,7 +71,7 @@ async def collections(request: Request):
7171
assert link["href"].startswith(url_prefix)
7272
assert {"next", "previous", "root", "self"} == {link["rel"] for link in links}
7373

74-
response = client.post(f"{endpoint_prefix}/search", json={})
74+
response = client.post(f"{prefix}/search", json={})
7575
assert response.status_code == 200
7676
assert response.json()["url"] == url_prefix + "/search"
7777
assert response.json()["base_url"].rstrip("/") == url_prefix
@@ -82,7 +82,7 @@ async def collections(request: Request):
8282
assert link["href"].startswith(url_prefix)
8383
assert {"next", "previous", "root", "self"} == {link["rel"] for link in links}
8484

85-
response = client.get(f"{endpoint_prefix}/collections")
85+
response = client.get(f"{prefix}/collections")
8686
assert response.status_code == 200
8787
assert response.json()["url"] == url_prefix + "/collections"
8888
assert response.json()["base_url"].rstrip("/") == url_prefix

tests/conftest.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import asyncio
21
import json
32
import logging
43
import os
@@ -62,11 +61,6 @@
6261
)
6362

6463

65-
@pytest.fixture(scope="session")
66-
def event_loop():
67-
return asyncio.get_event_loop()
68-
69-
7064
@pytest.fixture(scope="session")
7165
def database(postgresql_proc):
7266
with DatabaseJanitor(

0 commit comments

Comments
 (0)