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

Issue with absent trailing slash in stac-fastapi #343

Open
slesaad opened this issue Mar 25, 2024 · 4 comments
Open

Issue with absent trailing slash in stac-fastapi #343

slesaad opened this issue Mar 25, 2024 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@slesaad
Copy link
Member

slesaad commented Mar 25, 2024

Note: read discussion; some investigation has started

Description

A recent deployment of the veda-backend introduced an issue with the stac-fastapi where absence of a trailing slash causes it to respond with a 307 temporary redirect

See the behavior in
https://dev.openveda.cloud/api/stac vs https://dev.openveda.cloud/api/stac/

We ruled out any infrastructure issue by running it locally:

image
image

Downgrading to stac-fastapi.api==2.4.5 still has the same behavior

@amarouane-ABDELHAK @vincentsarago @wildintellect

@slesaad slesaad added the bug Something isn't working label Mar 25, 2024
@anayeaye
Copy link
Collaborator

Just a note: We've actually been seeing this bug for a long time in the dev instance so it is possible that it is unrelated to recent code changes:

https://dev.openveda.cloud/api/stac redirects to origin (https://dev.openveda.cloud which is a s3 website stac browser) while https://dev.openveda.cloud/api/stac/ properly directs to the stac api.

We hadn't prioritized this work because we didn't realize it was impacting users. We'd been assuming that it was tech debt in smoothing out our cloud front configuration. :(

@slesaad
Copy link
Member Author

slesaad commented Mar 28, 2024

Another issue I noticed, the "next" link isn't formed as expected, (look at the last link in the screenshot - missing /api/stac)

image

@anayeaye
Copy link
Collaborator

anayeaye commented Mar 29, 2024

For the pagination issue I think there is a missing self.resolve somewhere in the generation of the next link for pagination in v2.4 stac-fastapi. I'm looking to see if that gets fixed in later versions. Just dropping this note to :ack: the bug.

https://github.com/stac-utils/stac-fastapi/blob/2.4.0/stac_fastapi/pgstac/stac_fastapi/pgstac/models/links.py#L127

@anayeaye anayeaye self-assigned this Apr 24, 2024
@anayeaye
Copy link
Collaborator

#358

anayeaye added a commit that referenced this issue Apr 26, 2024
## What
Fix problem in which a stac-fastapi deployed behind a proxy (i.e.
`customdomain.com`) with a custom root path (i.e. `/api/stac`)
- Fixed: API does not properly resolve `customdomain.com/api/stac` ->
`customdomain.com/api/stac/`
- Fixed: API does not properly use custom root path in next links of
paginated responses `customdomain.com/api/stac/...` links are returned
as `customdomain.com/...` without the custom root path.

The correction is to remove the gateway configuration from the Mangum
ASGI handler for the stac-api handler.

### Refs
- [Fastapi behind a
proxy](https://fastapi.tiangolo.com/advanced/behind-a-proxy/#proxy-with-a-stripped-path-prefix)
- [Mangum configuring an adaptar instance with
api_gateway_base_path](https://mangum.io/adapter/#configuring-an-adapter-instance_)
pattern that we use and need for titiler/raster-api and ingest-api

### Issue

#343

### Testing?

- I deployed this change manually to the dev veda-backend stack and
confirmed that the stac-api url is properly resolved and that the next
links now properly include the root path.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants