-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
fix(gatsby-source-wordpress): adjust how endpoint urls are constructed to fix fetching for wordpress.com hosted sites and proxied urls #10624
Conversation
91549f0
to
cb58c74
Compare
cb58c74
to
1ad686b
Compare
## Description As reported in gatsbyjs#10427 some WordPress.com sites return a `_links.$.self` with a fullpath `https://public-api.wordpress.com/wp/v2/sites/$site/users/me` and others without `https://public-api.wordpress.com/`. This means it is not a reliable way of removing the `baseUrl` from the `fullUrl`. Instead we pass the route key in as the `fullPath` rather than the `fullUrl`. We then extract the `basePath` from the `baseUrl` before finally removing the `basePath` from the `fullPath`. We also need to extract the raw entity type from the `fullPath` rather than route. We also need to build the `fullUrl` from `baseUrl` and `fullPath` so I introduced the `buildFullUrl` function to do just that. I’ve included tests for both WordPress.com and WordPress.org. ## Related Issues Fixes gatsbyjs#10427.
1ad686b
to
eb43bee
Compare
This is pretty wild on wp.com side (maybe it was changed in .org / self-hosted too in recent wp version?). Do you perhaps have wp.com I could use to verify everything works correctly with proposed changes |
@pieh Thanks for taking a look. I've just DM'd you credentials on Twitter (sorry, couldn't find your email address). |
Status update - there are currently some issues with non-wp.com sites with proposed changes (missing There is support ticket https://en.forums.wordpress.com/topic/rest-api-returning-different-self-links/ created by PR author, but it wasn't responded yet, so I'd like to hold on a bit with taking action on this. For anyone else hitting the issue - in meantime You can use @lukemorton's fork of the plugin https://www.npmjs.com/package/@madetech/gatsby-source-wordpress that contains changes proposed in this PR. |
I can confirm this is not a bug on WordPress.com – I thought so too in the beginning. But after testing with Postman and removing See #11021 for more details. |
it does not seem that @lukemorton's PR working either :(
|
i investigated this a bit further, after adding the missing
|
Is this currently being worked on? I ended up resolving the issues by removing instances of _accessToken from the fetch.js file. |
what exactly you removed? The issue on my side was resolved aswell, but that was crealy an issue with the |
@zilahir I was referencing #11021 (comment) |
fa279e5
to
eb43bee
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @lukemorton!
Holy buckets, @lukemorton — we just merged your PR to Gatsby! 💪💜 Gatsby is built by awesome people like you. Let us say “thanks” in two ways:
If there’s anything we can do to help, please don’t hesitate to reach out to us: tweet at @gatsbyjs and we’ll come a-runnin’. Thanks again! |
Description
As reported in #10427 some WordPress.com sites return a
_links.$.self
with a fullpathhttps://public-api.wordpress.com/wp/v2/sites/$site/users/me
and others withouthttps://public-api.wordpress.com/
. This means it is not a reliable way of removing thebaseUrl
from thefullUrl
.Instead we pass the route key in as the
fullPath
rather than thefullUrl
. We then extract thebasePath
from thebaseUrl
before finally removing thebasePath
from thefullPath
.We also need to extract the raw entity type from the
fullPath
rather than route.We also need to build the
fullUrl
frombaseUrl
andfullPath
so I introduced thebuildFullUrl
function to do just that.I’ve included tests for both WordPress.com and WordPress.org.
Related Issues
Fixes #10427.