Skip to content

Commit

Permalink
Merge pull request #1043 from aligent/revert-1040-feature/JBH-615_set…
Browse files Browse the repository at this point in the history
…_is_a_bot_header

Revert "JBH-615: Set is a bot header"
  • Loading branch information
krishanthisera authored Mar 28, 2023
2 parents 210352b + 4f657ed commit 2c6cf64
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions packages/lambda-at-edge-handlers/lib/prerender-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,25 @@ export const handler = async (
): Promise<CloudFrontRequest> => {
let request = event.Records[0].cf.request;

/**
* If the request is from a bot, is not a file and is not from prerender
* then set the x-request-prerender header so the origin-request lambda function
* alters the origin to prerender.io
* "x-is-a-bot" header should be whitelisted in the respective behaviors
*/
if (IS_BOT.test(request.headers["user-agent"][0].value)) {
request.headers["x-is-a-bot"] = [
// If the request is from a bot, is not a file and is not from prerender
// then set the x-request-prerender header so the origin-request lambda function
// alters the origin to prerender.io
if (
!IS_FILE.test(request.uri) &&
IS_BOT.test(request.headers["user-agent"][0].value) &&
!request.headers["x-prerender"]
) {
request.headers["x-request-prerender"] = [
{
key: "x-is-a-bot",
key: "x-request-prerender",
value: "true",
},
];
if (!IS_FILE.test(request.uri) && !request.headers["x-prerender"]) {
request.headers["x-request-prerender"] = [
{
key: "x-request-prerender",
value: "true",
},
];

request.headers["x-prerender-host"] = [
{ key: "X-Prerender-Host", value: request.headers.host[0].value },
];
}
request.headers["x-prerender-host"] = [
{ key: "X-Prerender-Host", value: request.headers.host[0].value },
];
}

return request;
};

0 comments on commit 2c6cf64

Please sign in to comment.