Skip to content

Commit

Permalink
Fix frontend robots.txt (#4186)
Browse files Browse the repository at this point in the history
  • Loading branch information
zackkrida committed Apr 24, 2024
1 parent 96f56d7 commit f1477cc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 38 deletions.
4 changes: 4 additions & 0 deletions frontend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ src/locales/scripts/wp-locales.json
/.npmrc
/.pnpmfile.cjs
/pnpm-lock.yaml

# To prevent accidentally adding a hardcoded robots.txt, see
# /src/server-middleware/robots.js for the robots.txt file.
src/static/robots.txt
28 changes: 25 additions & 3 deletions frontend/src/server-middleware/robots.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,44 @@
const { LOCAL, PRODUCTION } = require("../constants/deploy-env")

const deniedUserAgents = [
"GPTBot",
"CCBot",
"ChatGPT-User",
"Google-Extended",
"anthropic-ai",
"Omgilibot",
"Omgili",
"FacebookBot",
"Diffbot",
"Bytespider",
"ImagesiftBot",
"cohere-ai",
]

const aiDisallowRules = deniedUserAgents
.map((ua) => `User-agent: ${ua}\nDisallow: /\n`)
.join("\n")

/**
* Send the correct robots.txt information per-environment.
*/
export default function robots(_, res) {
const deployEnv = process.env.DEPLOYMENT_ENV ?? LOCAL

const contents =
deployEnv === PRODUCTION
? `# Block search result pages
deployEnv !== PRODUCTION
? `# Block search result pages and single result pages
User-agent: *
Crawl-delay: 10
Disallow: /search/audio/
Disallow: /search/image/
Disallow: /search/
Disallow: /image/
Disallow: /audio/
${aiDisallowRules}
`
: `# Block crawlers from the staging site
: `# Block everyone from the staging site
User-agent: *
Disallow: /
`
Expand Down
35 changes: 0 additions & 35 deletions frontend/src/static/robots.txt

This file was deleted.

0 comments on commit f1477cc

Please sign in to comment.