Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
NebulaServices
GitHub Repository: NebulaServices/Nebula
Path: blob/main/src/pages/robots.txt.ts
976 views
1
import type { APIRoute } from "astro";
2
import { SEO } from "astro:env/client";
3
interface config {
4
enabled: boolean;
5
domain: string;
6
}
7
const SEOConfig: config = JSON.parse(SEO);
8
9
const genRobotsTXT = (sitemap: URL) => `
10
User-Agent: *
11
Allow: /
12
User-Agent: *
13
Disallow: /uv
14
SiteMap: ${sitemap.href}
15
`;
16
17
const otherDomainTXT = `
18
User-Agent: *
19
Disallow: /*
20
`
21
22
export const GET: APIRoute = ({ site, request }) => {
23
const url = new URL('sitemap-index.xml', site);
24
const host = new URL(request.url).host;
25
if (SEOConfig.enabled && host === SEOConfig.domain) {
26
return new Response(genRobotsTXT(url));
27
}
28
return new Response(otherDomainTXT);
29
};
30
31