diff --git a/next.config.js b/next.config.js index a4e116a7b..963dfefc6 100644 --- a/next.config.js +++ b/next.config.js @@ -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() { diff --git a/public/robots.txt b/public/robots.txt deleted file mode 100644 index ed48c036e..000000000 --- a/public/robots.txt +++ /dev/null @@ -1,9 +0,0 @@ -# * -User-agent: * -Allow: / - -# Host -Host: https://podkrepi.bg - -# Sitemaps -Sitemap: https://podkrepi.bg/sitemap.xml diff --git a/src/pages/api/robots.ts b/src/pages/api/robots.ts new file mode 100644 index 000000000..2596acc1e --- /dev/null +++ b/src/pages/api/robots.ts @@ -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) + } +}