import "server-only";

import { NextResponse } from "next/server";

/** Public content: CDN-cacheable for a minute, served stale while it refreshes. */
export const PUBLIC_CACHE = "public, max-age=0, s-maxage=60, stale-while-revalidate=600";

export function apiJson(body: unknown, { status = 200, cache = PUBLIC_CACHE }: { status?: number; cache?: string } = {}) {
  return NextResponse.json(body, {
    status,
    headers: {
      "cache-control": cache,
      // API responses are data for the website, not pages to index.
      "x-robots-tag": "noindex",
    },
  });
}

export const SLUG_PARAM = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
