Files
blitzkit/packages/website/src/pages/robots.txt.ts
T

19 lines
575 B
TypeScript
Raw Normal View History

2024-10-14 10:47:49 -05:00
import { assertSecret } from '@blitzkit/core';
import type { APIContext } from 'astro';
2025-04-03 12:23:53 -05:00
export async function GET({ request }: APIContext) {
2024-10-14 10:47:49 -05:00
const allowRobots = assertSecret(import.meta.env.ALLOW_ROBOTS) === 'true';
2025-04-03 12:23:53 -05:00
const flags: Record<string, string | null> = {
'User-agent': '*',
[allowRobots ? 'Allow' : 'Disallow']: '/',
space: null,
Sitemap: `${new URL(request.url).origin}/sitemap-index.xml`,
};
2024-10-14 10:47:49 -05:00
2024-11-17 12:29:57 -06:00
return new Response(
2025-04-03 12:23:53 -05:00
Object.entries(flags)
.map(([key, value]) => (value === null ? '' : `${key}: ${value}`))
.join('\n'),
2024-11-17 12:29:57 -06:00
);
2024-10-14 10:47:49 -05:00
}