Skip to content

Commit

Permalink
Add listeners to stop crawlers in dev envs
Browse files Browse the repository at this point in the history
  • Loading branch information
NiallJoeMaher authored Nov 18, 2023
1 parent 4a33159 commit 6b26504
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions cdk/lib/app-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,18 +157,29 @@ export class AppStack extends cdk.Stack {

if (!production) {
fargateService.listener.addAction("ListenerRule", {
priority: 10,
priority: 1,
conditions: [elbv2.ListenerCondition.pathPatterns(["/robots.txt"])],
action: elbv2.ListenerAction.fixedResponse(200, {
contentType: "text/plain",
messageBody: `User-agent: *
Disallow: /`.replace(/ +/g, ""),
}),
});

fargateService.listener.addAction("ListenerRule", {
priority: 2,
conditions: [elbv2.ListenerCondition.pathPatterns(["/sitemap.xml"])],
action: elbv2.ListenerAction.fixedResponse(404, {
contentType: "text/plain",
messageBody:
"404 Not Found: The requested URL /sitemap.xml was not found on this server.",
}),
});
}

fargateService.listener.addAction("HostListenerRule", {
priority: 1,
// priority updates if on dev enviornment to block crawlers
priority: !production ? 3 : 1,
conditions: [elbv2.ListenerCondition.hostHeaders(["*.codu.co"])],
action: elbv2.ListenerAction.forward([fargateService.targetGroup]),
});
Expand Down

0 comments on commit 6b26504

Please sign in to comment.