Skip to content

Commit 24fe213

Browse files
committed
Add endpoint configuration to support custom URLs.
1 parent ee17432 commit 24fe213

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/gatsby-node.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,9 @@ const createContentDigest = obj =>
1111
.digest('hex');
1212

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

16-
export async function sourceNodes(
17-
{ boundActionCreators, store, cache },
18-
pluginOptions
19-
) {
20-
const { createNode, touchNode } = boundActionCreators;
15+
export async function sourceNodes({ actions, store, cache }, pluginOptions) {
16+
const { createNode, touchNode } = actions;
2117

2218
const { aws: awsConfig, buckets: bucketsConfig } = await schema.validate(
2319
pluginOptions
@@ -34,7 +30,11 @@ export async function sourceNodes(
3430
const node = {
3531
...rest,
3632
...content,
37-
Url: `https://s3.${region ? `${region}.` : ''}amazonaws.com/${rest.Name}/${Key}`,
33+
Url: awsConfig.endpoint
34+
? `${awsConfig.endpoint.replace(/\/$/, '')}/${rest.Name}/${Key}`
35+
: `https://s3.${region ? `${region}.` : ''}amazonaws.com/${
36+
rest.Name
37+
}/${Key}`,
3838
id: `s3-${Key}`,
3939
children: [],
4040
parent: '__SOURCE__',

src/plugin-options.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ export const schema = yup.object().shape({
77
accessKeyId: yup.string(),
88
secretAccessKey: yup.string(),
99
sessionToken: yup.string(),
10+
endpoint: yup.string(),
1011
region: yup.string(),
1112
})
1213
.default(() => ({
1314
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
1415
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
1516
sessionToken: process.env.AWS_SESSION_TOKEN,
17+
endpoint: process.env.AWS_DOMAIN,
1618
region: process.env.AWS_REGION,
1719
})),
1820
buckets: yup.array().required(),

0 commit comments

Comments
 (0)