strata / frontend

The front of Headless CMS. Build an efficient front-end website taking content from multiple data sources.
MIT License
13 stars 5 forks source link

If a page only has one match, then you can end up with duplicate URLs #84

Open sean-dunwoody opened 4 years ago

sean-dunwoody commented 4 years ago

Describe the bug Duplicate URLs can be created when the API call to WordPress only matches one item.

To Reproduce

  1. Create a page in WordPress that sits on the second level of the site, e.g.

/about-us/the-team

  1. View this page in the frontend to see that it works.
  2. Manipuate the URL so that about-us changes to something else, e.g.

/any-value-in-here/the-team

  1. Page should be returned. This means the same content can be accessed on multiple duplicate (and incorrect URLs)

Expected behavior The page should only be returned when the exact request URL matches the full URL in WordPress

Additional context This only seems to happen when the WordPress API returns exactly one match. This is the endpoint in question:

/wp-json/wp/v2/pages?slug=/page-url-here/

This only requests the final segement of the URL, e.g. in the above example:

/about-us/the-team

The query would be:

/wp-json/wp/v2/pages?slug=/the-team/

If this API response returns more than one match, then this error doesn't occur.

I think this is related to the following recent changes:

https://github.com/strata/frontend/pull/83/files

simonrjones commented 4 years ago

Various fixes have been made to CCS to help resolve this.

However, full fix is to access WP API using the post type & post ID which should be possible once we have persistent metadata about pages. See #63