Skip to content

Commit

Permalink
feat(gatsby-source-wordpress): Ability to set a custom rest api route…
Browse files Browse the repository at this point in the history
… prefix (gatsbyjs#20998)

* ✨ Added configuration option to set a custom wp rest api route prefix

* 🐛 Fixed undefined varaible, added  to configuration options in README

* chore: format

* 🐛

Co-authored-by: GatsbyJS Bot <mathews.kyle+gatsbybot@gmail.com>
  • Loading branch information
crock and GatsbyJS Bot authored Feb 3, 2020
1 parent 5783cd1 commit 789fb1c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/gatsby-source-wordpress/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ module.exports = {
baseUrl: "live-gatbsyjswp.pantheonsite.io",
// The protocol. This can be http or https.
protocol: "https",
// The rest api route prefix that your WordPress site is using.
// Sometimes this is modified by WordPress plugins.
// If not set, it uses the default of "wp-json"
restApiRoutePrefix: "wp-json",
// Indicates whether the site is hosted on wordpress.com.
// If false, then the assumption is made that the site is self hosted.
// If true, then the plugin will source its content on wordpress.com using the JSON REST API V2.
Expand Down
3 changes: 2 additions & 1 deletion packages/gatsby-source-wordpress/src/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ async function fetch({
_concurrentRequests,
_includedRoutes,
_excludedRoutes,
_restApiRoutePrefix,
typePrefix,
refactoredEntityTypes,
}) {
Expand All @@ -65,7 +66,7 @@ async function fetch({
url = `https://public-api.wordpress.com/wp/v2/sites/${baseUrl}`
_accessToken = await getWPCOMAccessToken(_auth)
} else {
url = `${_siteURL}/wp-json`
url = `${_siteURL}/${_restApiRoutePrefix}`
if (shouldUseJwt(_auth)) {
_accessToken = await getJWToken(_auth, url)
}
Expand Down
5 changes: 5 additions & 0 deletions packages/gatsby-source-wordpress/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ let _excludedRoutes
let _normalizer
let _normalizers
let _keepMediaSizes
let _restApiRoutePrefix

exports.sourceNodes = async (
{
Expand Down Expand Up @@ -53,6 +54,7 @@ exports.sourceNodes = async (
normalizer,
normalizers,
keepMediaSizes = false,
restApiRoutePrefix = `wp-json`,
}
) => {
const { createNode, touchNode } = actions
Expand All @@ -70,6 +72,7 @@ exports.sourceNodes = async (
_includedRoutes = includedRoutes
_excludedRoutes = excludedRoutes
_keepMediaSizes = keepMediaSizes
_restApiRoutePrefix = restApiRoutePrefix
_normalizer = normalizer
_normalizers = normalizers

Expand All @@ -87,6 +90,7 @@ exports.sourceNodes = async (
_includedRoutes,
_excludedRoutes,
_keepMediaSizes,
_restApiRoutePrefix,
typePrefix,
refactoredEntityTypes,
})
Expand Down Expand Up @@ -240,6 +244,7 @@ exports.sourceNodes = async (
concurrentRequests,
excludedRoutes,
keepMediaSizes,
restApiRoutePrefix,
}

// apply custom normalizer
Expand Down

0 comments on commit 789fb1c

Please sign in to comment.