import type { MetadataRoute } from "next"; import { unstable_noStore as noStore } from "next/cache"; import { getMaintenanceMode, getSeoSettings } from "@/lib/app-config"; import { INTERNAL_ADMIN_PREFIX } from "@/lib/admin-routing"; import { getSiteUrl } from "@/lib/metadata"; export const dynamic = "force-dynamic"; /** Paths that must never be crawled even when indexing is enabled. */ export const ROBOTS_DISALLOWED_PATHS = [ INTERNAL_ADMIN_PREFIX, "/root", "/api/", "/success", "/coming-soon", "/*/success", "/*/coming-soon", ]; export function buildRobots(input: { indexable: boolean }): MetadataRoute.Robots { const siteUrl = getSiteUrl(); if (!input.indexable) { return { rules: [{ userAgent: "*", disallow: "/" }], host: siteUrl.origin, }; } return { rules: [ { userAgent: "*", allow: "/", disallow: ROBOTS_DISALLOWED_PATHS, }, ], sitemap: new URL("/sitemap.xml", siteUrl).toString(), host: siteUrl.origin, }; } export default async function robots(): Promise { noStore(); const [seo, maintenanceEnabled] = await Promise.all([getSeoSettings(), getMaintenanceMode()]); return buildRobots({ indexable: seo.allowIndexing && !maintenanceEnabled }); }