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

fix(gatsby-source-wordpress): fix WP-API-MENUS when reported endpoint url doesn't match base url #12859

Merged
merged 4 commits into from
Apr 13, 2019

Conversation

STUkh
Copy link
Contributor

@STUkh STUkh commented Mar 26, 2019

Description

This PR fixes case when wordpress site URL exists behind proxy or in docker-container with it's local own address and route.self links give us wrong URL that gatsby-source-wordpress try to fetch (and obviously fails).

Related Issues

For me it's fixes intercontainer communication, when wordpress hosted inside of docker with internal address http://localhost:8080, but for exposes as http://wordpress:8080 for other containers. Base URL fetched properly by gatsy-source-wordpress, but all internal self links are broken because rely on localhost instead of desired wordpress base host.

I see it should fixe the same problem described in #10427

@pieh
Copy link
Contributor

pieh commented Mar 26, 2019

Are you able to test changes from #10624 ? It touches similar problem and it might fix this issue as well.

It changes how endpoint urls are created - instead of using self links - it will use base url (for self hosted wordpress it will be url from config + /wp-json) and then appends just wordpress endpoint paths (so for example /wp/v2/posts) - seems like this will solve issue you described as well as it will use http://wordpress:8080 url

@pieh
Copy link
Contributor

pieh commented Mar 27, 2019

@STUkh Can you try using gatsby-source-wordpress@3.0.50? I merged PR linked above and I do believe it should fix this

@pieh pieh added the status: awaiting author response Additional information has been requested from the author label Mar 27, 2019
@STUkh
Copy link
Contributor Author

STUkh commented Mar 27, 2019

@pieh, thanks for answer, will try.

@STUkh
Copy link
Contributor Author

STUkh commented Mar 28, 2019

@pieh , now It works better, but fails in menus fetching
https://monosnap.com/file/UdFdxrO3KdFqczxTmRSIsguvCeQqZk

@pieh
Copy link
Contributor

pieh commented Mar 28, 2019

@STUkh We are getting close ;)

if (type == `wordpress__wp_api_menus_menus`) {
for (let menu of routeResponse) {
if (menu.meta && menu.meta.links && menu.meta.links.self) {
entities = entities.concat(
await fetchData({
route: { url: menu.meta.links.self, type: `${type}_items` },
_verbose,
_perPage,
_auth,
_accessToken,
})
)
}
}
}

Seems like this references links.self so we need to swap just this one. Are you able to share minimal docker-compose (or whatever) setup you are using so I could reproduce it?

@STUkh STUkh force-pushed the fix/wordpress-broken-route-self-links branch from e7c1f4a to e3e8d1a Compare March 29, 2019 09:18
@STUkh
Copy link
Contributor Author

STUkh commented Mar 29, 2019

@pieh updated PR content because of new PRs was merged. Fixed menus paths. Docker example project to reproduce bug: https://github.com/STUkh/gatsby-wordpress-docker
Not it uses local fixed version of gatsby-plugin-wordpress, so it will be easy to see changes.

@pieh pieh changed the title fix(gatsby-source-wordpress): broken route self links fix(gatsby-source-wordpress): fix WP-API-MENUS when reported endpoint url doesn't match base url Apr 13, 2019
@pieh pieh removed the status: awaiting author response Additional information has been requested from the author label Apr 13, 2019
Copy link
Contributor

@pieh pieh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @STUkh! Sorry I lost track of it, but just verified it and added some basic unit tests (mostly to document how it should behave rather than test it)

@pieh pieh merged commit a430202 into gatsbyjs:master Apr 13, 2019
@gatsbot
Copy link

gatsbot bot commented Apr 13, 2019

Holy buckets, @STUkh — we just merged your PR to Gatsby! 💪💜

Gatsby is built by awesome people like you. Let us say “thanks” in two ways:

  1. We’d like to send you some Gatsby swag. As a token of our appreciation, you can go to the Gatsby Swag Store and log in with your GitHub account to get a coupon code good for one free piece of swag. (Currently we’ve got a couple t-shirts available, plus some socks that are really razzing our berries right now.)
  2. We just invited you to join the Gatsby organization on GitHub. This will add you to our team of maintainers. Accept the invite by visiting https://github.com/orgs/gatsbyjs/invitation. By joining the team, you’ll be able to label issues, review pull requests, and merge approved pull requests.

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants