Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ As mentioned above, the `bucketName` is required, but there's much more to confi
| `retainObjectsPatterns` | `string array \| undefined` | `[]` | An array of file globs that should not be removed from the S3 bucket if the file does not exist locally, this does nothing unless `removeNonexistentObjects` is true. [See here for glob format](https://github.com/isaacs/node-glob#glob-primer) |
| `customAwsEndpointHostname` | `string \| undefined` | `amazonaws.com` | Custom AWS S3 endpoint. [See our docs for all available options](https://gatsby-plugin-s3.jari.io/recipes/custom-endpoint) |
| `enableS3StaticWebsiteHosting` | `boolean \| undefined` | `true` | Disables modifications to the S3 Static Website Hosting configuration. Without S3 Static Website Hosting some features (index.html rewriting, trailing slash redirects, and serverside redirects), will not function. Not recommended, but could be useful for preventing Cloud formation Stack Drift or suppressing Terraform noise if you don't need, the static website hosting functionality. |
| `indexDocumentSuffix` | `string \| undefined` | `index.html` | Index document suffix. See https://docs.aws.amazon.com/AmazonS3/latest/API/API_IndexDocument.html. |
| `errorDocumentKey` | `string \| undefined` | `404.html` | Error document object key name to use when a 4XX class error occurs. See https://docs.aws.amazon.com/AmazonS3/latest/API/API_ErrorDocument.html. |
| `parallelLimit` | `number \| undefined` | `20` | Max number of files to upload in parallel. |
| `maxRetries` | `number \| undefined` | `undefined` | The maximum amount of retries to perform for a service request. |
| `connectTimeout` | `number \| undefined` | `undefined` | The maximum time in milliseconds that the connection phase of the request should be allowed to take. This only limits the connection phase and has no impact once the socket has established a connection. |
Expand Down
2 changes: 2 additions & 0 deletions docs/.awesome/content/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ Default configuration is as follows:
retainObjectsPatterns: [],
customAwsEndpointHostname: undefined,
enableS3StaticWebsiteHosting: true,
indexDocumentSuffix: 'index.html',
errorDocumentKey: '404.html',
parallelLimit: 20,
maxRetries: undefined;
connectTimeout: undefined;
Expand Down
2 changes: 2 additions & 0 deletions examples/with-redirects/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ module.exports = {
: {}),
removeNonexistentObjects: true,
retainObjectsPatterns: ['**/*.retain.js', '**/retain-folder/*'],
indexDocumentSuffix: process.env.GATSBY_S3_INDEX_DOCUMENT_SUFFIX || 'index.html',
errorDocumentKey: process.env.GATSBY_S3_ERROR_DOCUMENT_KEY || '404.html',
},
},
{
Expand Down
11 changes: 11 additions & 0 deletions examples/with-redirects/src/pages/another404.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react';
import Layout from '../components/layout';

const NotFoundPage = () => (
<Layout>
<h1>ANOTHER NOT FOUND</h1>
<p>You just hit a route that doesn&#39;t exist... the sadness.</p>
</Layout>
);

export default NotFoundPage;
24 changes: 24 additions & 0 deletions gatsby-plugin-s3-e2e-tests/src/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,3 +374,27 @@ describe('with pathPrefix', () => {
});
});
});

describe('custom error document', () => {
beforeAll(async () => {
await buildSite('gatsby-plugin-s3-example-with-redirects', {
GATSBY_S3_TARGET_BUCKET: bucketName,
GATSBY_S3_ERROR_DOCUMENT_KEY: 'another404.html',
});
await deploySite('gatsby-plugin-s3-example-with-redirects', [
Permission.PutObject,
Permission.PutObjectAcl,
Permission.CreateBucket,
Permission.PutBucketAcl,
Permission.PutBucketWebsite,
]);
});

test(`uses custom error document`, async () => {
const path = `${testingEndpoint}/random`;
const response = await fetch(path);
expect(response.status, `This path should not exist ${path}`).toBe(404);
const html = await response.text();
expect(html.indexOf('ANOTHER'), `Wrong error document used`).toBeGreaterThan(0);
});
});
4 changes: 2 additions & 2 deletions gatsby-plugin-s3/src/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,10 @@ export const deploy = async ({ yes, bucket, userAgent }: DeployArguments = {}) =
Bucket: config.bucketName,
WebsiteConfiguration: {
IndexDocument: {
Suffix: 'index.html',
Suffix: config.indexDocumentSuffix ?? 'index.html',
},
ErrorDocument: {
Key: '404.html',
Key: config.errorDocumentKey ?? '404.html',
},
},
};
Expand Down
7 changes: 7 additions & 0 deletions gatsby-plugin-s3/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ export interface S3PluginOptions extends PluginOptions {
// the static website hosting functionality.
enableS3StaticWebsiteHosting?: boolean;

// Index document suffix. See https://docs.aws.amazon.com/AmazonS3/latest/API/API_IndexDocument.html.
indexDocumentSuffix?: string;

// Error document object key name to use when a 4XX class error occurs.
// See https://docs.aws.amazon.com/AmazonS3/latest/API/API_ErrorDocument.html.
errorDocumentKey?: string;

// Max number of files to upload in parallel.
parallelLimit?: number;

Expand Down