Gatsby: [gatsby-source-wordpress] Error in includedRoutes documentation ?

Created on 6 Jan 2019  路  6Comments  路  Source: gatsbyjs/gatsby

Hi,

I try to use includedRoutes option of gatsby-source-wordpress plugin but could not make it work following the documentation here : https://www.gatsbyjs.org/packages/gatsby-source-wordpress/.

I added these lines in my gatsby-config.json file :

includedRoutes: [
    "/*/*/categories",
    "/*/*/posts",
    "/*/*/pages",
    "/*/*/tags",
    "/*/*/taxonomies",
    "/*/*/users",
],

But when I run gastby develop and enable verbose output I have such unexpected messages :

Route discovered : /wp/v2/posts
Excluded route: not whitelisted

I debugged the plugin and found that the following method in fetch.js file :

function checkRouteList(routePath, routeList) {
  return routeList.some(route => minimatch(routePath, route));
}

As you can see that this method uses the route path including base url (for example https://mywebsite.com/wp-json/v2/posts) and this doesn't match /*/*/posts.

I had to change gatsby-config.js this way to make it work :

includedRoutes: [
    "**/*/*/categories",
    "**/*/*/posts",
    "**/*/*/pages",
    "**/*/*/tags",
    "**/*/*/taxonomies",
    "**/*/*/users",
],

Is this an error in the documentation ? Or is there something I didn't understand ? (I am surprised I found nothing about this problem)

good first issue documentation

Most helpful comment

Hello, is it okay if I can take this issue?
Pull request can be viewed here - https://github.com/gatsbyjs/gatsby/pull/10887

All 6 comments

Thank you for opening this @chawax 馃檪

This definitely looks like an issue with the documentation. We would love to receive a pull request fixing this! Would you be interested?

The file that needs to be updated is at https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-source-wordpress/README.md

Hello, is it okay if I can take this issue?
Pull request can be viewed here - https://github.com/gatsbyjs/gatsby/pull/10887

I had no issues with the glob patterns of documentation. But I didn't exclude anything. Is this only relevant to routes of which some endpoints have been excluded?

Like:

includedRoutes: [
  '/*/*/posts',
],
excludedRoutes: [
  '/*/*/posts/1234',
],

@chawax I just checked and currently documented route globs works for me (TM), but my routes looks like /wp/v2/posts (without protocol + host like in your example), did you set protocol option in gatsby-config to https?

In either case there is no harm in adjusting docs to use ** (it still works in my tests) but maybe we could look into why discovered routes differ.

@cardiv
By default includedRoutes glob is just ** meaning we will try to grab everything - you can use it to narrow it down to only things you are interested in (especially when you have lots of plugins installed that add lot of 3rd party rest endpoints that would make fetching data just take a lot of time). Also important is that we don't hit individual post endpoints ('/*/*/posts/1234') - we grab all the data from listing ('/*/*/posts')

@pieh I set protocol to https. I tried with http too but behaviour is the same. As I said I was surprised no one encountered the problem before. So it may come from my environment.

I saw minimatch lib is used to check the route name. I have version 3.0.2 in node_modules. I don't know if it can be part of the problem, but I work on OSX. And my node version is 10.13.0.

@pieh, I'm using the plugin on a wordpress.com hosted site and I'm trying to include e.g. whitelist some routes.

getRoutePath strips the base url from the route and then it is checked via checkRouteList.

In my case it ends up checking for example /pages, so neither the new **/*/*/pages or the old /*/*/pages would do the trick.

The working configuration:

{
  resolve: `gatsby-source-wordpress`,
  options: {
    baseUrl: `stoffwindelberatungjuliarose.wordpress.com`,
    protocol: `https`,
    hostingWPCOM: true,
    useACF: false,
    auth: {
      // [...]
    },
    includedRoutes: ['/pages*', '/media*'],
  },
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  3Comments

totsteps picture totsteps  路  3Comments

jimfilippou picture jimfilippou  路  3Comments

Oppenheimer1 picture Oppenheimer1  路  3Comments

hobochild picture hobochild  路  3Comments