Skip to content

Commit 69d82cd

Browse files
committed
Make the robots.txt file dynamic in order to pull domain from config.
1 parent 1731e2f commit 69d82cd

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

public/robots.txt

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/pages/robots.txt.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import type { APIRoute } from 'astro';
2+
3+
const getRobotsTxt = (sitemapURL: URL) => `
4+
User-agent: *
5+
Allow: /
6+
7+
Disallow: /api/*
8+
9+
Sitemap: ${sitemapURL.href}
10+
`;
11+
12+
export const GET: APIRoute = ({ site }) => {
13+
const sitemapURL = new URL('sitemap-index.xml', site);
14+
return new Response(getRobotsTxt(sitemapURL));
15+
};

0 commit comments

Comments
 (0)