Skip to content

Commit

Permalink
make the robots.txt file dynamic (podkrepi-bg#1680)
Browse files Browse the repository at this point in the history
  • Loading branch information
yyosifov authored and RalitsaIlieva committed Dec 14, 2023
1 parent cf2bbd5 commit 5238461
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
4 changes: 4 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ const moduleExports = {
source: '/api/v1/:slug*',
destination: `${process.env.API_URL ?? 'http://localhost:5010/api/v1'}/:slug*`, // Proxy to API
},
{
source: '/robots.txt',
destination: '/api/robots'
}
]
},
async redirects() {
Expand Down
9 changes: 0 additions & 9 deletions public/robots.txt

This file was deleted.

24 changes: 24 additions & 0 deletions src/pages/api/robots.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { NextApiRequest, NextApiResponse } from 'next'

const productionRobotsContent = `# *
User-agent: *
Allow: /
# Host
Host: https://podkrepi.bg
# Sitemaps
Sitemap: https://podkrepi.bg/sitemap.xml
`

const devRobotsContent = `User-agent: *
Disallow: /
`

export default async (req: NextApiRequest, res: NextApiResponse) => {
if (process.env.APP_ENV === 'production') {
res.status(200).send(productionRobotsContent)
} else {
res.status(200).send(devRobotsContent)
}
}

0 comments on commit 5238461

Please sign in to comment.