Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirect browse fix #9

Merged
merged 6 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docker-compose.local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ services:
environment:
- base_address_http=http://localhost
- base_address_https=https://localhost
- base_browse_address=https://staging.knowwheregraph.org/browse
networks:
- kwg_network
5 changes: 3 additions & 2 deletions docker-compose.prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ services:
ports:
- '8080:8080'
environment:
- base_address_http=http://stko-kwg.geog.ucsb.edu
- base_address_https=https://stko-kwg.geog.ucsb.edu
- base_address_http=http://kwg-api:8080
- base_address_https=https://kwg-api:8080
- base_browse_address=https://stko-kwg.geog.ucsb.edu/browse
networks:
- kwg_network
5 changes: 3 additions & 2 deletions docker-compose.stage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ services:
ports:
- '8080:8080'
environment:
- base_address_http=http://staging.knowwheregraph.org
- base_address_https=https://staging.knowwheregraph.org
- base_address_http=http://kwg-api:8080
- base_address_https=https://kwg-api:8080
- base_browse_address=https://staging.knowwheregraph.org/browse
networks:
- kwg_network
4 changes: 1 addition & 3 deletions kwg_api/api/node_negotiator.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,9 @@ def _redirect_browse(self) -> RedirectResponse:

:return: A response signaling a redirect to a URL
"""
browse_url = f"{self.base_address_https}/browse/"
resource_id_shortened = PrefixBuilder.resolve_prefix(
self.request_url, self.resource_id
)
if not resource_id_shortened:
resource_id_shortened = self.resource_id
print(self.base_address_https)
return RedirectResponse(url=f"{browse_url}#{resource_id_shortened}")
return RedirectResponse(url=f"{self.base_browse_address}#{resource_id_shortened}")
1 change: 1 addition & 0 deletions kwg_api/lib/content_negotiator.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def __init__(self, request: Request, resource_id: str):
"""
self.base_address_http = os.getenv("base_address_http")
self.base_address_https = os.getenv("base_address_https")
self.base_browse_address = os.getenv("base_browse_address")
accept_header = request.headers.get("accept")
if not accept_header:
raise ValueError("Failed to read the request headers")
Expand Down
1 change: 0 additions & 1 deletion kwg_api/lib/prefix_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ def resolve_prefix(full_uri: str | URL, resource_id: str) -> str | None:
# Split the resource out of the . It should look like
# {base_address}/lod/resource/
base_url = str(full_uri).split(resource_id)[0]

except IndexError:
logging.warning(
f"Failed to find a prefix for URI {full_uri}", exc_info=True
Expand Down