Skip to content

Commit

Permalink
Merge pull request #1041 from aligent/feature/JBH-615_set_is_a_bot_he…
Browse files Browse the repository at this point in the history
…ader

JBH-615: Set is a bot header in prerender proxy repo
  • Loading branch information
krishanthisera authored Mar 28, 2023
2 parents c4b9134 + 243f781 commit 210352b
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions packages/prerender-proxy/lib/handlers/prerender-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,24 @@ export const handler = async (event: CloudFrontRequestEvent): Promise<CloudFront
// 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-request-prerender',
value: 'true'
}
];
if (IS_BOT.test(request.headers['user-agent'][0].value)) {
request.headers["x-is-a-bot"] = [
{
key: "x-is-a-bot",
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;
Expand Down

0 comments on commit 210352b

Please sign in to comment.