diff --git a/packages/prerender-fargate/lib/prerender-fargate-options.ts b/packages/prerender-fargate/lib/prerender-fargate-options.ts index 0b78678a..4d292f20 100644 --- a/packages/prerender-fargate/lib/prerender-fargate-options.ts +++ b/packages/prerender-fargate/lib/prerender-fargate-options.ts @@ -94,6 +94,12 @@ export interface PrerenderFargateOptions { * @default - true */ enableRecache?: boolean; + /** + * Let Headless Chrome send "x-prerender" header in the request. + * Ensure CORS allows the header. + * @default - true + */ + enablePrerenderHeader?: boolean; } /** diff --git a/packages/prerender-fargate/lib/prerender-fargate.ts b/packages/prerender-fargate/lib/prerender-fargate.ts index e11df50c..7542a0e5 100644 --- a/packages/prerender-fargate/lib/prerender-fargate.ts +++ b/packages/prerender-fargate/lib/prerender-fargate.ts @@ -89,6 +89,7 @@ export class PrerenderFargate extends Construct { prerenderFargateScalingOptions, prerenderFargateRecachingOptions, enableRecache, + enablePrerenderHeader, } = props; // Create bucket for prerender storage @@ -133,6 +134,7 @@ export class PrerenderFargate extends Construct { S3_BUCKET_NAME: this.bucket.bucketName, AWS_REGION: Stack.of(this).region, ENABLE_REDIRECT_CACHE: enableRedirectCache?.toString() || "false", + ENABLE_PRERENDER_HEADER: enablePrerenderHeader?.toString() || "true", }; const secrets = { diff --git a/packages/prerender-fargate/lib/prerender/server.js b/packages/prerender-fargate/lib/prerender/server.js index 32eb02d0..bdb97197 100644 --- a/packages/prerender-fargate/lib/prerender/server.js +++ b/packages/prerender-fargate/lib/prerender/server.js @@ -64,9 +64,13 @@ server.use({ server.use(prerender.blacklist()); -// Let headless chrome send 'X-Prerender: 1' in the request for any specicial handling such as disabling geo-redirection. -// Ensure that the "access-control-allow-headers" header of any backend systems allows "x-prerender" if CORS is configured. -server.use(prerender.sendPrerenderHeader()); +if (process.env.ENABLE_PRERENDER_HEADER.toLowerCase() === 'true'){ + + // Let headless chrome send 'X-Prerender: 1' in the request for any specicial handling such as disabling geo-redirection. + // Ensure that the "access-control-allow-headers" header of any backend systems allows "x-prerender" if CORS is configured. + + server.use(prerender.sendPrerenderHeader()); +} if (process.env.ENABLE_REDIRECT_CACHE.toLowerCase() === 'true'){ var he = require('he');