Skip to content

Commit 5a2e542

Browse files
authored
fix: cloudfront function regex and return request (#246)
1 parent 2193608 commit 5a2e542

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/NextjsDistribution.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ export class NextjsDistribution extends Construct {
334334
}
335335

336336
private useCloudFrontFunctionHostHeader() {
337-
return `event.request.headers["x-forwarded-host"] = event.request.headers.host;`;
337+
return ` event.request.headers["x-forwarded-host"] = event.request.headers.host;`;
338338
}
339339

340340
private useCloudFrontFunctionCacheHeaderKey() {
@@ -373,7 +373,7 @@ export class NextjsDistribution extends Construct {
373373
? event.request.cookies["__prerender_bypass"].value
374374
: "";
375375
}
376-
const crypto = require("crypto")
376+
const crypto = require("crypto");
377377
const hashedKey = crypto.createHash("md5").update(cacheKey).digest("hex");
378378
event.request.headers["x-open-next-cache-key"] = { value: hashedKey };
379379
`;
@@ -390,14 +390,15 @@ export class NextjsDistribution extends Construct {
390390
async function handler(event) {
391391
// INJECT_CLOUDFRONT_FUNCTION_HOST_HEADER
392392
// INJECT_CLOUDFRONT_FUNCTION_CACHE_HEADER_KEY
393+
return event.request;
393394
}
394395
`;
395396
code = code.replace(
396-
/^\s*\/\/\s*INJECT_CLOUDFRONT_FUNCTION_HOST_HEADER.*$/i,
397+
/^\s*\/\/\s*INJECT_CLOUDFRONT_FUNCTION_HOST_HEADER.*$/im,
397398
this.useCloudFrontFunctionHostHeader()
398399
);
399400
code = code.replace(
400-
/^\s*\/\/\s*INJECT_CLOUDFRONT_FUNCTION_CACHE_HEADER_KEY.*$/i,
401+
/^\s*\/\/\s*INJECT_CLOUDFRONT_FUNCTION_CACHE_HEADER_KEY.*$/im,
401402
this.useCloudFrontFunctionCacheHeaderKey()
402403
);
403404
const cloudFrontFn = new cloudfront.Function(this, 'CloudFrontFn', {

0 commit comments

Comments
 (0)