Skip to content

Generate env specific robots.txt#507

Merged
sarangj merged 1 commit into
qafrom
robots-ts
Jan 15, 2026
Merged

Generate env specific robots.txt#507
sarangj merged 1 commit into
qafrom
robots-ts

Conversation

@sarangj

@sarangj sarangj commented Jan 14, 2026

Copy link
Copy Markdown
Contributor

Ticket:

This PR does the following:

Use the nextJS robots.ts setup to create separate robots.txt files per environment. For non-prod environments, set a disallow on everything to prevent google from indexing qa.

Open questions

How has this been tested? How should a reviewer test this?

See the generated robots file on vercel: https://digital-collections-git-robots-ts-nypl.vercel.app/robots.txt

Accessibility concerns or updates

Checklist:

  • I have added relevant accessibility documentation for this pull request.
  • All new and existing tests passed.
  • I have updated the CHANGELOG.md.

Use the nextJS `robots.ts` setup to create separate `robots.txt` files
per environment. For non-prod environments, set a disallow on everything
to prevent google from indexing qa.
@vercel

vercel Bot commented Jan 14, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
digital-collections Ready Ready Preview, Comment Jan 14, 2026 7:50pm

@emu47 emu47 requested a review from Copilot January 15, 2026 15:29

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements environment-specific robots.txt generation using Next.js's robots.ts functionality to prevent search engine indexing of non-production environments while maintaining selective bot blocking in production.

Changes:

  • Removed static robots.txt file from public directory
  • Added dynamic robots.ts handler that generates environment-specific rules
  • Configured complete disallow for non-production environments to prevent indexing

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
public/robots.txt Removed static robots.txt file to enable dynamic generation
app/robots.ts Added dynamic robots handler with environment-specific rules

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app/robots.ts
Comment on lines +5 to +20
return {
rules: [
{
userAgent: "Bytedance",
disallow: "/",
},
{
userAgent: "Bytespider",
disallow: "/",
},
{
userAgent: "GPTBot",
disallow: "/",
},
],
};

Copilot AI Jan 15, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The production rules block specific bots but don't specify behavior for other crawlers. This means bots like Googlebot will have unrestricted access by default. Consider adding an explicit rule for '*' user agent with 'allow: /' to make the intent clear, or add 'allow' rules for the blocked bots if they should only be blocked from specific paths.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gonna ignore this to maintain the exact existing robots.txt

Comment thread app/robots.ts
Comment on lines +25 to +28
rules: {
userAgent: "*",
disallow: "/",
},

Copilot AI Jan 15, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rules property should be an array to match the MetadataRoute.Robots type definition and maintain consistency with the production configuration. Change 'rules: {' to 'rules: [{' and close with '}]'.

Suggested change
rules: {
userAgent: "*",
disallow: "/",
},
rules: [
{
userAgent: "*",
disallow: "/",
},
],

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Robots type can be an array or single object, gonna ignore this

@sarangj sarangj merged commit f178f08 into qa Jan 15, 2026
5 checks passed
@sarangj sarangj deleted the robots-ts branch January 15, 2026 18:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants