← back to Stayclaim
src/app/robots.ts
37 lines
import type { MetadataRoute } from 'next';
import { headers } from 'next/headers';
import { siteForHost } from '@/lib/site';
import { FREE_FOREVER } from '@/lib/flags';
export const runtime = 'nodejs';
export const dynamic = 'force-dynamic';
/**
* robots.txt — host-aware. Each surface (wholivedthere/claimmyaddress/bubbesblock)
* gets its own robots block rooted at its base URL. Owner/admin/promo flows
* disallowed; retired pay surfaces (/hosts, /promote) disallowed when FREE_FOREVER.
*/
export default async function robots(): Promise<MetadataRoute.Robots> {
const h = await headers();
const surface = siteForHost(h.get('x-pastdoor-host') || h.get('host'));
// Always derive base from the resolved surface — never NEXT_PUBLIC_BASE_URL,
// which would point all 3 surfaces' robots.txt at one domain's sitemap.
// siteForHost is null-tolerant and returns DEFAULT_SURFACE for unknown hosts.
const base = `https://${surface.domain}`;
const baseDisallow = ['/api/', '/dashboard/', '/claim/', '/submit', '/browse?'];
const retiredDisallow = FREE_FOREVER ? ['/hosts/', '/promote/'] : [];
return {
rules: [
{
userAgent: '*',
allow: ['/'],
disallow: [...baseDisallow, ...retiredDisallow],
},
],
sitemap: `${base}/sitemap.xml`,
host: base,
};
}