From 670a8e1feefa86d646b6cc8ba2b5d4c04a0e5ae0 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Fri, 15 Sep 2023 14:30:21 +0930 Subject: [PATCH] introduce flag for enabling redirect cache --- packages/prerender-fargate/README.md | 27 ++++++++++--------- .../lib/prerender-fargate.ts | 2 ++ .../prerender-fargate/lib/prerender/server.js | 2 +- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/packages/prerender-fargate/README.md b/packages/prerender-fargate/README.md index f8a325f6..97c9cae6 100644 --- a/packages/prerender-fargate/README.md +++ b/packages/prerender-fargate/README.md @@ -1,15 +1,18 @@ # Prerender in Fargate -A construct to host [Prerender](https://github.com/prerender/prerender) in Fargate. + +A construct to host [Prerender](https://github.com/prerender/prerender) in Fargate. ## Props - - `prerenderName`: Name of the Prerender service - - `domainName`: Domain name for Prerender - - `vpcId`: VPC to host Prerender in - - `bucketName`: Optional S3 bucket name - - `expirationDays`: Optional days until items expire in bucket (default to 7 days) - - `tokenList`: List of tokens to accept as authentication - - `certificateArn`: Certificate arn to match the domain - - `desiredInstanceCount`: Number of Prerender instances to run (default 1) - - `maxInstanceCount`: Maximum number of Prerender instances to run (default 2) - - `instanceCPU`: CPU to allocate to each instance (default 512) - - `instanceMemory`: Amount of memory to allocate to each instance (default 1024) + +- `prerenderName`: Name of the Prerender service +- `domainName`: Domain name for Prerender +- `vpcId`: VPC to host Prerender in +- `bucketName`: Optional S3 bucket name +- `expirationDays`: Optional days until items expire in bucket (default to 7 days) +- `tokenList`: List of tokens to accept as authentication +- `certificateArn`: Certificate arn to match the domain +- `desiredInstanceCount`: Number of Prerender instances to run (default 1) +- `maxInstanceCount`: Maximum number of Prerender instances to run (default 2) +- `instanceCPU`: CPU to allocate to each instance (default 512) +- `instanceMemory`: Amount of memory to allocate to each instance (default 1024) +- `enableRedirectCache`: Cache 301 and 302 responses, too (default false) diff --git a/packages/prerender-fargate/lib/prerender-fargate.ts b/packages/prerender-fargate/lib/prerender-fargate.ts index b1d86a92..07e33b91 100644 --- a/packages/prerender-fargate/lib/prerender-fargate.ts +++ b/packages/prerender-fargate/lib/prerender-fargate.ts @@ -22,6 +22,7 @@ export interface PrerenderOptions { maxInstanceCount?: number, instanceCPU?: number, instanceMemory?: number + enableRedirectCache?: string } export class PrerenderFargate extends Construct { @@ -80,6 +81,7 @@ export class PrerenderFargate extends Construct { AWS_ACCESS_KEY_ID: accessKey.accessKeyId, AWS_SECRET_ACCESS_KEY: accessKey.secretAccessKey.toString(), AWS_REGION: Stack.of(this).region, + ENABLE_REDIRECT_CACHE: props.enableRedirectCache || "false", TOKEN_LIST: props.tokenList.toString() } }, diff --git a/packages/prerender-fargate/lib/prerender/server.js b/packages/prerender-fargate/lib/prerender/server.js index c744d794..215ad2cc 100644 --- a/packages/prerender-fargate/lib/prerender/server.js +++ b/packages/prerender-fargate/lib/prerender/server.js @@ -37,7 +37,7 @@ server.use({ server.use(prerender.blacklist()); -if (process.env.ENABLE_CACHE_FOR_REDIRECTION){ +if (process.env.ENABLE_REDIRECT_CACHE.toLowerCase() === 'true'){ server.use(prerender.removeScriptTags()); var he = require('he'); var s3 = new (require('aws-sdk')).S3({params:{Bucket: process.env.S3_BUCKET_NAME}});