Skip to content

Commit

Permalink
introduce flag for enabling redirect cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Park committed Sep 15, 2023
1 parent a86b5a9 commit 670a8e1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
27 changes: 15 additions & 12 deletions packages/prerender-fargate/README.md
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 2 additions & 0 deletions packages/prerender-fargate/lib/prerender-fargate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface PrerenderOptions {
maxInstanceCount?: number,
instanceCPU?: number,
instanceMemory?: number
enableRedirectCache?: string
}

export class PrerenderFargate extends Construct {
Expand Down Expand Up @@ -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()
}
},
Expand Down
2 changes: 1 addition & 1 deletion packages/prerender-fargate/lib/prerender/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}});
Expand Down

0 comments on commit 670a8e1

Please sign in to comment.