Skip to content

Commit

Permalink
Add endpoint configuration to support custom URLs.
Browse files Browse the repository at this point in the history
  • Loading branch information
mplabs committed Jul 19, 2021
1 parent ee17432 commit 24fe213
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,9 @@ const createContentDigest = obj =>
.digest('hex');

const isImage = object => /\.(jpe?g|png|webp|tiff?)$/i.test(object);
const getBucketName = () => {};

export async function sourceNodes(
{ boundActionCreators, store, cache },
pluginOptions
) {
const { createNode, touchNode } = boundActionCreators;
export async function sourceNodes({ actions, store, cache }, pluginOptions) {
const { createNode, touchNode } = actions;

const { aws: awsConfig, buckets: bucketsConfig } = await schema.validate(
pluginOptions
Expand All @@ -34,7 +30,11 @@ export async function sourceNodes(
const node = {
...rest,
...content,
Url: `https://s3.${region ? `${region}.` : ''}amazonaws.com/${rest.Name}/${Key}`,
Url: awsConfig.endpoint
? `${awsConfig.endpoint.replace(/\/$/, '')}/${rest.Name}/${Key}`
: `https://s3.${region ? `${region}.` : ''}amazonaws.com/${
rest.Name
}/${Key}`,
id: `s3-${Key}`,
children: [],
parent: '__SOURCE__',
Expand Down
2 changes: 2 additions & 0 deletions src/plugin-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ export const schema = yup.object().shape({
accessKeyId: yup.string(),
secretAccessKey: yup.string(),
sessionToken: yup.string(),
endpoint: yup.string(),
region: yup.string(),
})
.default(() => ({
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
sessionToken: process.env.AWS_SESSION_TOKEN,
endpoint: process.env.AWS_DOMAIN,
region: process.env.AWS_REGION,
})),
buckets: yup.array().required(),
Expand Down

0 comments on commit 24fe213

Please sign in to comment.