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

feat(gatsby-source-drupal): Provide proxyUrl in addition to baseUrl to allow using CDN, API gateway, etc. #36819

Merged
merged 19 commits into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions packages/gatsby-source-drupal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,27 @@ module.exports = {
}
```

## CDN

You can add an optional CDN or API gateway URL `proxyUrl` param. The URL can be a simple proxy of the Drupal
`baseUrl`, or another URL (even containing a path) where the Drupal JSON API resources can be retrieved.
Vacilando marked this conversation as resolved.
Show resolved Hide resolved

```javascript
// In your gatsby-config.js
module.exports = {
plugins: [
{
resolve: `gatsby-source-drupal`,
options: {
baseUrl: `https://live-contentacms.pantheonsite.io/`,
proxyUrl: `https://xyz.cloudfront.net/`,
apiBase: `api`, // optional, defaults to `jsonapi`
},
},
],
}
```

## GET Search Params

You can append optional GET request params to the request url using `params` option.
Expand Down
9 changes: 9 additions & 0 deletions packages/gatsby-source-drupal/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ exports.sourceNodes = async (
globalReporter = reporter
const {
baseUrl,
proxyUrl = baseUrl,
apiBase = `jsonapi`,
basicAuth = {},
filters,
Expand Down Expand Up @@ -534,6 +535,11 @@ ${JSON.stringify(webhookBody, null, 4)}`
}
}

// If proxyUrl is defined, use it instead of baseUrl to get the content.
if (proxyUrl !== baseUrl) {
url = url.replace(baseUrl, proxyUrl)
}

let d
try {
d = await requestQueue.push([
Expand Down Expand Up @@ -833,6 +839,9 @@ exports.pluginOptionsSchema = ({ Joi }) =>
baseUrl: Joi.string()
.required()
.description(`The URL to root of your Drupal instance`),
proxyUrl: Joi.string().description(
`The CDN URL equivalent to your baseUrl`
),
apiBase: Joi.string().description(
`The path to the root of the JSONAPI — defaults to "jsonapi"`
),
Expand Down