From 5df5358768d896dfa104157181670ef989e69193 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Smoli=C5=84ski?= Date: Thu, 26 Nov 2026 10:38:29 +0100 Subject: [PATCH] Revert "A development host is kept out of search engines without IAPL_NOINDEX (developmentNoindex, default on)" This reverts commit bc3aac249f67fdff98d0561bde4ace69f531330f. --- docs/CHANGELOG.md | 11 --- docs/agent/AGENT.md | 2 +- docs/agent/skills/iapl-reference/SKILL.md | 2 +- docs/agent/skills/iapl-setup/SKILL.md | 2 +- docs/agent/skills/iapl-upgrade/SKILL.md | 5 -- docs/deployment.md | 4 +- docs/security.md | 2 +- .../.agents/skills/iapl-reference/SKILL.md | 2 +- reference/.agents/skills/iapl-setup/SKILL.md | 2 +- .../.agents/skills/iapl-upgrade/SKILL.md | 5 -- src/modules/email/relay/session.ts | 5 +- src/modules/security/buildSecurityHeaders.ts | 17 +---- src/modules/seo/buildMetadata.ts | 2 +- src/modules/seo/buildRobots.ts | 4 +- src/modules/seo/indexNow.ts | 2 +- src/modules/seo/siteNoindex.ts | 46 ++--------- src/modules/shared/developmentHosts.ts | 18 ----- src/plugin.ts | 2 - src/types.ts | 9 --- test/indexNow.test.ts | 10 --- test/mailRelay.test.ts | 4 - test/plugin.test.ts | 7 -- test/seo.test.ts | 76 ------------------- 23 files changed, 24 insertions(+), 215 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 8e82563..9a8df66 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -32,15 +32,6 @@ once there are more than 20. - **Nothing else has to be run.** The e-mail tab of Site integrations has a new block ("How e-mails are sent"); it is rendered by the status banner already in every import map, so `generate:importmap` gives no diff. No field was added; "Sending method" keeps its two stored values. -- **What changes for an existing site on upgrade — search engines, on a development host only:** a site whose - address (`NEXT_PUBLIC_SERVER_URL`) matches `iapl({ developmentHosts })` — built in: `*.dev.netscale.pl` — is now - **noindex without `IAPL_NOINDEX`**: robots.txt answers `Disallow: /`, every page carries `noindex, nofollow`, - `buildSecurityHeaders()` adds `X-Robots-Tag: noindex, nofollow`, IndexNow sends nothing. Until now nothing kept a - development copy out of search engines unless somebody set the variable. A site on its real domain is not - affected, and at launch the rule ends by itself with the address. An SEO check (Lighthouse, `iapl-seo-check`) run - against the development address now reports the noindex — run it with `IAPL_NOINDEX=0`, or against the real - domain. To keep the old behaviour: `iapl({ developmentNoindex: false })` (the project), `IAPL_NOINDEX=0` (one - environment), `buildSecurityHeaders({ developmentHosts: false })` (the header). - **What changes for an existing site on upgrade — e-mail:** | Site today | After the upgrade | Opt-out | @@ -120,8 +111,6 @@ once there are more than 20. project replaces the list with its own patterns or empties it (`[]`). Building blocks: `matchDevelopmentHost`, `isDevelopmentHost`, `pluginDevelopmentHosts`, `siteIsNonPublic`, `siteNonPublicSignal` (`NonPublicSignal`). Doctor: `mail-non-public` (info, deep) names the signal that makes a site non-public. -- **Plugin option `developmentNoindex`** (default `true`): a development host is kept out of search engines - without `IAPL_NOINDEX` (above). `buildSecurityHeaders({ developmentHosts, serverUrl })` for the header. - **Panel:** the state block on the e-mail tab (transport in effect, the site's state with the service, sender and reply address, what is left of the limits, a replaced sender name; "Check now", "Connect again", "Disconnect"; "Enter an access key" for a token issued by hand only with `mail.relay.accessKeyField: true`); "Sending method" reads "Automatic" / "Microsoft Graph (deprecated)"; the server field reads diff --git a/docs/agent/AGENT.md b/docs/agent/AGENT.md index 29bdcc9..053162c 100644 --- a/docs/agent/AGENT.md +++ b/docs/agent/AGENT.md @@ -333,7 +333,7 @@ one is better. Google ignores the same description on many pages. | "Thank you" after a form, a confirmation page | **yes** | | internal search results, filter/parameter pages | **yes** (+ `disallowParams` in robots) | | a test page, a draft page, a landing page only for a paid campaign | **yes** | -| staging, preview, a test copy of the whole site | **`IAPL_NOINDEX=1` in that environment's env** — not the checkbox. A **development host** needs nothing: an address that matches `iapl({ developmentHosts })` (default `['*.dev.netscale.pl']`) is noindex by itself — robots.txt, page meta, IndexNow, and `X-Robots-Tag` from `buildSecurityHeaders()` (pass it `developmentHosts` too if the project changed the list; `next.config` runs before the plugin). Off: `iapl({ developmentNoindex: false })`, or `IAPL_NOINDEX=0` in one environment. Verify: `curl -sI https:/// \| grep -i x-robots-tag` and `/robots.txt` says `Disallow: /`; on the real domain neither | +| staging, preview, a test copy of the whole site | **`IAPL_NOINDEX=1` in that environment's env** — not the checkbox | | homepage, archives (blog, projects) | **never** — the panel blocks saving | | services, offer, contact, about us, posts | **never** | | privacy policy, cookies, terms | **no** by default (they are a credibility signal, they do no harm); `noindex` only at the client's request | diff --git a/docs/agent/skills/iapl-reference/SKILL.md b/docs/agent/skills/iapl-reference/SKILL.md index 88b1844..187cdde 100644 --- a/docs/agent/skills/iapl-reference/SKILL.md +++ b/docs/agent/skills/iapl-reference/SKILL.md @@ -266,7 +266,7 @@ The plugin's own variables are `IAPL_`; a deploy that sets the spelling fr | `IAPL_IP_HEADER` | `ipHeader: true` + production | rate limit trusts any IP header (spoofing) + warning in prod | env: `cf-connecting-ip` (Cloudflare) / `x-forwarded-for` (Traefik/nginx) | | `IAPL_COOKIE_SCAN_URL`, `IAPL_COOKIE_SCAN_TOKEN` | `cookieScanner.crawl` (`iaplEnvRules({ cookieCrawl: true })` requires both in production; token ≥ 16 chars) | **Check site** disabled, the box names the missing variable | env; the token also goes into the scanner service's `IAPL_CRAWLER_SITES` as `host=token` | | `IAPL_DOCTOR_TOKEN` | no; ≥ 32 characters | `GET /api/ipal/doctor` answers 404; with it the endpoint answers a Bearer token, and `iapl-doctor --url` with the same variable reads the deep counts | env (Coolify) and the doctor's shell; also read by the doctor: `CI`, `NO_COLOR`, `PAYLOAD_CONFIG_PATH` (`--deep`), `IAPL_DOCTOR_IMPORT_MAP` (internal) — doctor.md | -| `IAPL_NOINDEX` | no; `1`/`true`/`yes` **staging/preview only**; `0` = not noindex although on a development host | — (when set: robots Disallow, meta noindex, `X-Robots-Tag`, IndexNow sends nothing). A host matching `iapl({ developmentHosts })` (default `*.dev.netscale.pl`) is noindex without it (`developmentNoindex: false` to switch off) | staging env | +| `IAPL_NOINDEX` | no; `1`/`true`/`yes` **staging/preview only** | — (when set: robots Disallow, meta noindex, `X-Robots-Tag`, IndexNow sends nothing) | staging env | | `NEXT_PHASE` | set by Next | only tells `next build` from runtime: during the build an unreachable database gives an empty sitemap; at runtime the sitemap throws (route → 503) | do not set by hand | | `NEXT_RUNTIME` | set by Next | `instrumentation.ts` checks for `nodejs`; missing (scripts, seed) → `buildRevalidateHook` does not revalidate | do not set by hand | diff --git a/docs/agent/skills/iapl-setup/SKILL.md b/docs/agent/skills/iapl-setup/SKILL.md index ae6c1e5..c8584be 100644 --- a/docs/agent/skills/iapl-setup/SKILL.md +++ b/docs/agent/skills/iapl-setup/SKILL.md @@ -529,7 +529,7 @@ overrides the default; CSP: `buildCsp` flags (`youtube`, `googleMaps`, `metaPixe = no policy; after clean reports `mode: 'enforce'` (site and admin); nonces only for pages that already render per request (`createProxy({ csp })` + ``); `withSecurityConfig(config, { hidePoweredBy: false })` keeps `X-Powered-By`; `buildImagesConfig({ extraHosts })`; env validation is fully opt-in — filter/add rules -(`iaplEnvRules(…).filter(…)`). Staging: `IAPL_NOINDEX=1` (also stops IndexNow); a development address under `iapl({ developmentHosts })` (default `*.dev.netscale.pl`) is noindex by itself, nothing to set — check `/robots.txt` there says `Disallow: /` and on the real domain it does not. Search engines: `robots` instead of +(`iaplEnvRules(…).filter(…)`). Staging: `IAPL_NOINDEX=1` (also stops IndexNow). Search engines: `robots` instead of `getRobots` ignores the panel; `iapl({ searchSettings: false })` removes the tab; per-bot exceptions in code: `createContentHelpers({ robots: { aiBotRules: [{ userAgent, access }] } })`. Sitemap: `sitemapOptions: { maxUrls, cacheControl, memoSeconds }`, `sitemapEntries: (entries) => entries` (add/remove URLs), `underConstructionSeo: false`. diff --git a/docs/agent/skills/iapl-upgrade/SKILL.md b/docs/agent/skills/iapl-upgrade/SKILL.md index 3ea5358..4805138 100644 --- a/docs/agent/skills/iapl-upgrade/SKILL.md +++ b/docs/agent/skills/iapl-upgrade/SKILL.md @@ -581,11 +581,6 @@ PROGRAMISTA §6, item 73; email.md; AGENT.md §7.2) — nothing to run; read whi signal (`mail-non-public`). A copy on another host without the variable sends to the real addresses in its data; keep a copy silent for good with `mail: { relay: false }` or SMTP to a catcher. Production must not have `IAPL_NOINDEX` set (it would send nothing). - **A development address is now noindex by itself** (host matches `iapl({ developmentHosts })`, default - `*.dev.netscale.pl`): robots.txt `Disallow: /`, page meta, `X-Robots-Tag`, no IndexNow — with no `IAPL_NOINDEX`. - Nothing to do; tell the owner if an SEO check is run against the development address (use `IAPL_NOINDEX=0` - there, or the real domain). A project with its own list passes it to `buildSecurityHeaders({ developmentHosts })` - in `next.config` too. Old behaviour: `iapl({ developmentNoindex: false })`. 4. Code that compared the result of `payload.sendEmail` needs no change for SMTP and Graph. A send through the mail service returns `{ sent, transport: 'relay', … }`; `sent: false` with `confirmed: false` means "may have been sent". 5. Your own account mail (invitations): mark it — `withMailKind(message, 'account')`. Form mail and Payload's diff --git a/docs/deployment.md b/docs/deployment.md index 9bf055b..9c7677c 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -115,7 +115,7 @@ URLs point at that domain. Outside production, `R2_PUBLIC_URL` alone → read-on | `NEXT_PUBLIC_TURNSTILE_SITE_KEY`, `TURNSTILE_SECRET_KEY` | ⬜ | forms | fallback when the Turnstile keys are not in Site integrations. **`TURNSTILE_SECRET_KEY` is deprecated** — put the secret key into the panel (turnstile.md); the variable keeps working until a later, announced release | | `INDEXNOW_KEY` | ⬜ | SEO | IndexNow key (takes precedence over the key from the panel) | | `IAPL_COOKIE_SCAN_URL`, `IAPL_COOKIE_SCAN_TOKEN` | ⬜ (✅ prod with `iaplEnvRules({ cookieCrawl: true })`) | consent | cookie crawl (`cookieScanner.crawl`): the shared scanner service's URL and this site's token ([cookie-scanner.md](./cookie-scanner.md#browser-crawl)) | -| `IAPL_NOINDEX` | ⬜ | SEO | `1`/`true`/`yes` **on staging only** — the whole site is noindex (robots, meta, `X-Robots-Tag`). Not needed on a development host: a site whose `NEXT_PUBLIC_SERVER_URL` matches `iapl({ developmentHosts })` (built in: `*.dev.netscale.pl`) is noindex by itself; `0` there switches that off for the environment, `iapl({ developmentNoindex: false })` for the project | +| `IAPL_NOINDEX` | ⬜ | SEO | `1`/`true`/`yes` **on staging only** — the whole site is noindex (robots, meta, `X-Robots-Tag`) | | `IAPL_DOCTOR_TOKEN` | ⬜ | ops | ≥ 32 characters turns on the `iapl-doctor` status endpoint `GET /api/ipal/doctor` (404 without it) — [doctor.md](./doctor.md) | "✅ prod" = required by `iaplEnvRules({ storage: true })` / `({ ipHeader: true })` with @@ -318,7 +318,7 @@ checkbox; default: both). A changed variable takes effect only after a **redeplo | `DATABASE_URI`, `PAYLOAD_SECRET` | ✅ only if the build prerenders from the database (§3a3), otherwise ⬜ | ✅ | SSG (`generateStaticParams`) needs the database during `pnpm build`; DB-reading routes stay `force-dynamic` either way (§3b) | | `R2_*`, `GRAPH_*`, `TURNSTILE_SECRET_KEY`, `INDEXNOW_KEY`, `IAPL_IP_HEADER` | ⬜ | ✅ | read at runtime only — keep secrets out of the build | | `NODE_ENV` | — | — | do not set by hand: `next build` / `next start` use `production` | -| `IAPL_NOINDEX` | — | ✅ staging only (a development host needs none) | never on production | +| `IAPL_NOINDEX` | — | ✅ staging only | never on production | Multiline values (keys) → mark *Multiline*; values containing `$` → mark *Literal* (otherwise Coolify interpolates them). Coolify adds its own variables (`COOLIFY_FQDN`, `COOLIFY_URL`, `SOURCE_COMMIT`, `PORT`, `HOST`) — do not use diff --git a/docs/security.md b/docs/security.md index 8f22a72..6697c5b 100644 --- a/docs/security.md +++ b/docs/security.md @@ -61,7 +61,7 @@ export default withPayload(withSecurityConfig(nextConfig)) | `csp` | `false` | `buildCsp` args → the CSP header (+ `Reporting-Endpoints` with `reportUri`) | | `additional` | `[]` | extra headers; the same key overrides (also the `csp` ones) | -With `IAPL_NOINDEX=1` (staging), or on a development host — the site's address (`serverUrl`, default `NEXT_PUBLIC_SERVER_URL`) matches `developmentHosts` (default `['*.dev.netscale.pl']`, Intecion's development domain) — `X-Robots-Tag: noindex, nofollow` is added to every response. `next.config` runs before the plugin, so a project that changed `iapl({ developmentHosts })` passes the same list: `buildSecurityHeaders({ developmentHosts: [...] })`; `developmentHosts: false` or `IAPL_NOINDEX=0` leaves the header out. +With `IAPL_NOINDEX=1` (staging), `X-Robots-Tag: noindex, nofollow` is added to every response. **Uploads:** `buildUploadSecurityHeaders({ collections = ['media'] })` returns `headers()` rules for `/api//file/*` (sandbox, no scripts) — an SVG from local disk cannot run a script on the site's diff --git a/reference/.agents/skills/iapl-reference/SKILL.md b/reference/.agents/skills/iapl-reference/SKILL.md index 88b1844..187cdde 100644 --- a/reference/.agents/skills/iapl-reference/SKILL.md +++ b/reference/.agents/skills/iapl-reference/SKILL.md @@ -266,7 +266,7 @@ The plugin's own variables are `IAPL_`; a deploy that sets the spelling fr | `IAPL_IP_HEADER` | `ipHeader: true` + production | rate limit trusts any IP header (spoofing) + warning in prod | env: `cf-connecting-ip` (Cloudflare) / `x-forwarded-for` (Traefik/nginx) | | `IAPL_COOKIE_SCAN_URL`, `IAPL_COOKIE_SCAN_TOKEN` | `cookieScanner.crawl` (`iaplEnvRules({ cookieCrawl: true })` requires both in production; token ≥ 16 chars) | **Check site** disabled, the box names the missing variable | env; the token also goes into the scanner service's `IAPL_CRAWLER_SITES` as `host=token` | | `IAPL_DOCTOR_TOKEN` | no; ≥ 32 characters | `GET /api/ipal/doctor` answers 404; with it the endpoint answers a Bearer token, and `iapl-doctor --url` with the same variable reads the deep counts | env (Coolify) and the doctor's shell; also read by the doctor: `CI`, `NO_COLOR`, `PAYLOAD_CONFIG_PATH` (`--deep`), `IAPL_DOCTOR_IMPORT_MAP` (internal) — doctor.md | -| `IAPL_NOINDEX` | no; `1`/`true`/`yes` **staging/preview only**; `0` = not noindex although on a development host | — (when set: robots Disallow, meta noindex, `X-Robots-Tag`, IndexNow sends nothing). A host matching `iapl({ developmentHosts })` (default `*.dev.netscale.pl`) is noindex without it (`developmentNoindex: false` to switch off) | staging env | +| `IAPL_NOINDEX` | no; `1`/`true`/`yes` **staging/preview only** | — (when set: robots Disallow, meta noindex, `X-Robots-Tag`, IndexNow sends nothing) | staging env | | `NEXT_PHASE` | set by Next | only tells `next build` from runtime: during the build an unreachable database gives an empty sitemap; at runtime the sitemap throws (route → 503) | do not set by hand | | `NEXT_RUNTIME` | set by Next | `instrumentation.ts` checks for `nodejs`; missing (scripts, seed) → `buildRevalidateHook` does not revalidate | do not set by hand | diff --git a/reference/.agents/skills/iapl-setup/SKILL.md b/reference/.agents/skills/iapl-setup/SKILL.md index ae6c1e5..c8584be 100644 --- a/reference/.agents/skills/iapl-setup/SKILL.md +++ b/reference/.agents/skills/iapl-setup/SKILL.md @@ -529,7 +529,7 @@ overrides the default; CSP: `buildCsp` flags (`youtube`, `googleMaps`, `metaPixe = no policy; after clean reports `mode: 'enforce'` (site and admin); nonces only for pages that already render per request (`createProxy({ csp })` + ``); `withSecurityConfig(config, { hidePoweredBy: false })` keeps `X-Powered-By`; `buildImagesConfig({ extraHosts })`; env validation is fully opt-in — filter/add rules -(`iaplEnvRules(…).filter(…)`). Staging: `IAPL_NOINDEX=1` (also stops IndexNow); a development address under `iapl({ developmentHosts })` (default `*.dev.netscale.pl`) is noindex by itself, nothing to set — check `/robots.txt` there says `Disallow: /` and on the real domain it does not. Search engines: `robots` instead of +(`iaplEnvRules(…).filter(…)`). Staging: `IAPL_NOINDEX=1` (also stops IndexNow). Search engines: `robots` instead of `getRobots` ignores the panel; `iapl({ searchSettings: false })` removes the tab; per-bot exceptions in code: `createContentHelpers({ robots: { aiBotRules: [{ userAgent, access }] } })`. Sitemap: `sitemapOptions: { maxUrls, cacheControl, memoSeconds }`, `sitemapEntries: (entries) => entries` (add/remove URLs), `underConstructionSeo: false`. diff --git a/reference/.agents/skills/iapl-upgrade/SKILL.md b/reference/.agents/skills/iapl-upgrade/SKILL.md index 3ea5358..4805138 100644 --- a/reference/.agents/skills/iapl-upgrade/SKILL.md +++ b/reference/.agents/skills/iapl-upgrade/SKILL.md @@ -581,11 +581,6 @@ PROGRAMISTA §6, item 73; email.md; AGENT.md §7.2) — nothing to run; read whi signal (`mail-non-public`). A copy on another host without the variable sends to the real addresses in its data; keep a copy silent for good with `mail: { relay: false }` or SMTP to a catcher. Production must not have `IAPL_NOINDEX` set (it would send nothing). - **A development address is now noindex by itself** (host matches `iapl({ developmentHosts })`, default - `*.dev.netscale.pl`): robots.txt `Disallow: /`, page meta, `X-Robots-Tag`, no IndexNow — with no `IAPL_NOINDEX`. - Nothing to do; tell the owner if an SEO check is run against the development address (use `IAPL_NOINDEX=0` - there, or the real domain). A project with its own list passes it to `buildSecurityHeaders({ developmentHosts })` - in `next.config` too. Old behaviour: `iapl({ developmentNoindex: false })`. 4. Code that compared the result of `payload.sendEmail` needs no change for SMTP and Graph. A send through the mail service returns `{ sent, transport: 'relay', … }`; `sent: false` with `confirmed: false` means "may have been sent". 5. Your own account mail (invitations): mark it — `withMailKind(message, 'account')`. Form mail and Payload's diff --git a/src/modules/email/relay/session.ts b/src/modules/email/relay/session.ts index 878c9d7..483ee7b 100644 --- a/src/modules/email/relay/session.ts +++ b/src/modules/email/relay/session.ts @@ -5,7 +5,7 @@ import { randomBytes } from 'node:crypto' import type { RelayOptions, ResolvedRelayOptions } from './options.js' import { PLUGIN_VERSION } from '../../../version.js' -import { noindexEnv } from '../../seo/siteNoindex.js' +import { isSiteNoindex } from '../../seo/siteNoindex.js' import { matchDevelopmentHost } from '../../shared/developmentHosts.js' import { type RelayAnswer, type RelayRefusal, relayRequest } from './client.js' import { RELAY_CONFIRM_PATH, RELAY_DEFAULTS, RELAY_PRODUCT, type RelayStatusCode, relayStatusFor } from './constants.js' @@ -108,8 +108,7 @@ export type NonPublicSignal = { by: 'development-host'; pattern: string } | { by export function siteNonPublicSignal(payload: BasePayload, options: Pick): NonPublicSignal | null { const pattern = matchDevelopmentHost(relayHost(payload, options), options.developmentHosts ?? pluginDevelopmentHosts(payload)) if (pattern) {return { by: 'development-host', pattern }} - // the variable itself: whether a development host is ALSO kept out of search engines is another question - return noindexEnv() === true ? { by: 'noindex' } : null + return isSiteNoindex() ? { by: 'noindex' } : null } /** Is this site a non-public copy (`siteNonPublicSignal` as a yes or no)? */ diff --git a/src/modules/security/buildSecurityHeaders.ts b/src/modules/security/buildSecurityHeaders.ts index 1f99b3a..6d4a92a 100644 --- a/src/modules/security/buildSecurityHeaders.ts +++ b/src/modules/security/buildSecurityHeaders.ts @@ -1,7 +1,6 @@ import type { BuildCspArgs } from './buildCsp.js' import { isSiteNoindex } from '../seo/siteNoindex.js' -import { DEFAULT_DEVELOPMENT_HOSTS } from '../shared/developmentHosts.js' import { buildCspHeaders } from './buildCsp.js' /** @@ -30,14 +29,6 @@ export type BuildSecurityHeadersArgs = { * reports, then `mode: 'enforce'` (the only change). See docs/security.md. */ csp?: BuildCspArgs | false - /** - * Development-host patterns for the noindex header: a site whose address (`serverUrl`) matches gets - * `X-Robots-Tag: noindex, nofollow` without `IAPL_NOINDEX`. Default: the plugin's built-in list - * (`DEFAULT_DEVELOPMENT_HOSTS`, `['*.dev.netscale.pl']`). `next.config` runs before the plugin, so a - * project that changed `iapl({ developmentHosts })` passes the same list here; `false` = the variable - * alone decides. - */ - developmentHosts?: false | string[] /** * X-Frame-Options value. 'DENY' (default) blocks all framing; 'SAMEORIGIN' * allows same-origin framing. Note: CSP frame-ancestors supersedes this in @@ -65,8 +56,6 @@ export type BuildSecurityHeadersArgs = { permissionsPolicy?: null | string /** Referrer-Policy. Default 'strict-origin-when-cross-origin' (browser default, explicit). */ referrerPolicy?: null | string - /** The site's address, for `developmentHosts`. Default: `NEXT_PUBLIC_SERVER_URL`. */ - serverUrl?: string } /** @@ -104,9 +93,7 @@ export function buildSecurityHeaders(args: BuildSecurityHeadersArgs = {}): Secur hstsPreload = false, permissionsPolicy = 'camera=(), microphone=(), geolocation=()', referrerPolicy = 'strict-origin-when-cross-origin', - serverUrl, } = args - const developmentHosts = args.developmentHosts ?? DEFAULT_DEVELOPMENT_HOSTS const headers: SecurityHeader[] = [] @@ -137,8 +124,8 @@ export function buildSecurityHeaders(args: BuildSecurityHeadersArgs = {}): Secur headers.push({ key: 'Cross-Origin-Opener-Policy', value: coop }) } - // Staging / preview (IAPL_NOINDEX=1) or a development host: keep every response out of search engines. - if (isSiteNoindex({ developmentHosts, host: serverUrl })) { + // Staging / preview (IAPL_NOINDEX=1): keep every response out of search engines. + if (isSiteNoindex()) { headers.push({ key: 'X-Robots-Tag', value: 'noindex, nofollow' }) } diff --git a/src/modules/seo/buildMetadata.ts b/src/modules/seo/buildMetadata.ts index b57b780..c976c0e 100644 --- a/src/modules/seo/buildMetadata.ts +++ b/src/modules/seo/buildMetadata.ts @@ -213,7 +213,7 @@ export function buildMetadata({ // robots: noindex pages are excluded (follow keeps link authority). Indexed // pages get generous snippet/preview limits so Google can show rich results // (long snippets, large image previews, full video previews). - ...(isSiteNoindex({ host: origin }) + ...(isSiteNoindex() ? { robots: { follow: false, index: false } } : noindex || meta?.noindex ? { robots: { follow: true, index: false } } diff --git a/src/modules/seo/buildRobots.ts b/src/modules/seo/buildRobots.ts index 0c9ee47..a391824 100644 --- a/src/modules/seo/buildRobots.ts +++ b/src/modules/seo/buildRobots.ts @@ -140,8 +140,8 @@ export function buildRobots({ sitemap = true, }: BuildRobotsArgs): RobotsRules { const origin = baseUrl.replace(/\/$/, '') - // Staging / preview (IAPL_NOINDEX=1) or a development host (iapl({ developmentHosts })): nothing may be crawled. - if (isSiteNoindex({ host: origin })) {return { rules: { disallow: ['/'], userAgent: '*' } }} + // Staging / preview (IAPL_NOINDEX=1): nothing may be crawled. + if (isSiteNoindex()) {return { rules: { disallow: ['/'], userAgent: '*' } }} const defaults = [...(adminRoute ? [adminRoute] : []), '/api'] const paramRules = disallowParams diff --git a/src/modules/seo/indexNow.ts b/src/modules/seo/indexNow.ts index 7090b7c..9175aea 100644 --- a/src/modules/seo/indexNow.ts +++ b/src/modules/seo/indexNow.ts @@ -87,7 +87,7 @@ export function createIndexNowKeyRoute({ getCachedPayload }: { getCachedPayload: */ function publicOrigin(baseUrl?: string): null | string { const origin = (baseUrl ?? process.env.NEXT_PUBLIC_SERVER_URL ?? '').replace(/\/$/, '') - if (isSiteNoindex({ host: origin })) {return null} + if (isSiteNoindex()) {return null} if (process.env.NODE_ENV !== 'production' || !/^https:\/\//i.test(origin)) {return null} if (/localhost|127\.0\.0\.1|\.local\b|\.test\b/i.test(origin)) {return null} return origin diff --git a/src/modules/seo/siteNoindex.ts b/src/modules/seo/siteNoindex.ts index 201109d..5ae6b3a 100644 --- a/src/modules/seo/siteNoindex.ts +++ b/src/modules/seo/siteNoindex.ts @@ -1,49 +1,19 @@ -import { isDevelopmentHost, noindexDevelopmentHosts } from '../shared/developmentHosts.js' import { readEnv } from '../shared/envName.js' /** - * Whole-site noindex for development, staging, preview and test copies. Then robots.txt disallows everything, - * every page gets `robots: noindex, nofollow`, buildSecurityHeaders adds `X-Robots-Tag: noindex, nofollow` to - * every response (files and API too), and IndexNow sends nothing. - * - * Two ways in: - * - `IAPL_NOINDEX=1` in that environment's env (the old spelling IPAL_NOINDEX is still read); - * - by host, with no env: the site's address (`NEXT_PUBLIC_SERVER_URL`) matches a development pattern — - * `iapl({ developmentHosts })`, built in `*.dev.netscale.pl`. A development copy indexed by Google is a - * duplicate of the real site, and nothing else keeps it out. - * `IAPL_NOINDEX=0` (or `false`, `no`, `off`) says otherwise for one environment; `iapl({ developmentNoindex: - * false })` switches the host rule off for the project. Production never sets the variable and is on no - * development host. + * Whole-site noindex for staging, previews and test copies: set IAPL_NOINDEX=1 + * in that environment's env (the old spelling IPAL_NOINDEX is still read). Then robots.txt disallows everything, every page + * gets `robots: noindex, nofollow`, and buildSecurityHeaders adds + * `X-Robots-Tag: noindex, nofollow` to every response (files and API too). + * Production never sets it — a forgotten staging copy indexed by Google is a + * duplicate of the real site. */ /** The variable's name before 1.17.0. Still read; kept under this constant so `process.env[SITE_NOINDEX_ENV]` in a project means what it meant. */ export const SITE_NOINDEX_ENV = 'IPAL_NOINDEX' /** The variable's name since 1.17.0. Read it with `isSiteNoindex()` or `readEnv(IAPL_SITE_NOINDEX_ENV)`, which fall back to the old one. */ export const IAPL_SITE_NOINDEX_ENV = 'IAPL_NOINDEX' -/** What the variable says: `true` (1 / true / yes), `false` (0 / false / no / off), or `undefined` when it says nothing. */ -export function noindexEnv(): boolean | undefined { +export function isSiteNoindex(): boolean { const v = readEnv(IAPL_SITE_NOINDEX_ENV)?.trim().toLowerCase() - if (v === '1' || v === 'true' || v === 'yes') {return true} - if (v === '0' || v === 'false' || v === 'no' || v === 'off') {return false} - return undefined -} - -export type SiteNoindexArgs = { - /** The development patterns to go by; `false` = the variable alone decides. Default: the plugin's list. */ - developmentHosts?: false | readonly string[] - /** The site's address or host. Default: `NEXT_PUBLIC_SERVER_URL`. */ - host?: null | string -} - -/** Which signal makes the site noindex: the variable, its development host, or nothing. */ -export function siteNoindexSignal(args: SiteNoindexArgs = {}): 'development-host' | 'env' | null { - const env = noindexEnv() - if (env !== undefined) {return env ? 'env' : null} - const patterns = args.developmentHosts ?? noindexDevelopmentHosts() - if (patterns === false) {return null} - return isDevelopmentHost(args.host || process.env.NEXT_PUBLIC_SERVER_URL, patterns) ? 'development-host' : null -} - -export function isSiteNoindex(args: SiteNoindexArgs = {}): boolean { - return siteNoindexSignal(args) !== null + return v === '1' || v === 'true' || v === 'yes' } diff --git a/src/modules/shared/developmentHosts.ts b/src/modules/shared/developmentHosts.ts index 6ea9540..3a6383f 100644 --- a/src/modules/shared/developmentHosts.ts +++ b/src/modules/shared/developmentHosts.ts @@ -42,21 +42,3 @@ export function matchDevelopmentHost(host: null | string | undefined, patterns: /** Is `host` a development address (`matchDevelopmentHost` as a yes or no)? */ export const isDevelopmentHost = (host: null | string | undefined, patterns: readonly string[] = DEFAULT_DEVELOPMENT_HOSTS): boolean => matchDevelopmentHost(host, patterns) !== null - -// What `iapl({ developmentHosts, developmentNoindex })` set for this process — read by the helpers that run -// without a Payload config at hand (robots, metadata, IndexNow). `next.config` runs before the plugin: there, -// `buildSecurityHeaders({ developmentHosts })` takes the same list when the project changed it. -let configured: { hosts?: readonly string[]; noindex?: boolean } = {} - -/** Called by the plugin with its options; a later call replaces the earlier one. */ -export function configureDevelopmentHosts(options: { hosts?: readonly string[]; noindex?: boolean } = {}): void { - configured = { ...(options.hosts ? { hosts: [...options.hosts] } : {}), ...(options.noindex === false ? { noindex: false } : {}) } -} - -/** - * The patterns whose hosts are kept out of search engines by default: the plugin's development hosts, or - * `false` when the project switched that off (`iapl({ developmentNoindex: false })`). - */ -export function noindexDevelopmentHosts(): false | readonly string[] { - return configured.noindex === false ? false : (configured.hosts ?? DEFAULT_DEVELOPMENT_HOSTS) -} diff --git a/src/plugin.ts b/src/plugin.ts index e441626..0cc8df9 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -66,7 +66,6 @@ import { buildIndexNowHook } from './modules/seo/indexNow.js' import { searchSettingsFields } from './modules/seo/searchSettings.js' import { migrateTitleSeparator } from './modules/seo/titleSeparator.js' import { applyCollectionOverride } from './modules/shared/collectionOverride.js' -import { configureDevelopmentHosts } from './modules/shared/developmentHosts.js' import { buildStatsCollection, buildStatsEndpoint } from './modules/stats/index.js' import { visitorCookieFor } from './modules/stats/visitorCookie.js' @@ -753,7 +752,6 @@ export const iapl = (options: IaplOptions): Plugin => { // --- e-mail: the Intecion Notifications Webservice (docs/email.md; off with mail: { relay: false }) --- // What mailAdapter() reads at send time; born under the new name (`custom.iapl`). - configureDevelopmentHosts({ hosts: Array.isArray(options.developmentHosts) ? options.developmentHosts : undefined, noindex: options.developmentNoindex }) const relay = options.mail?.relay const iaplCustom = (config.custom?.iapl ?? {}) as object config.custom = { diff --git a/src/types.ts b/src/types.ts index c68ce0e..9eade1c 100644 --- a/src/types.ts +++ b/src/types.ts @@ -145,15 +145,6 @@ export type IaplOptions = { */ developmentHosts?: string[] - /** - * A site on a development host (`developmentHosts`) is kept out of search engines without - * `IAPL_NOINDEX`: robots.txt disallows everything, pages carry `noindex, nofollow`, IndexNow sends - * nothing (and `buildSecurityHeaders()` adds `X-Robots-Tag`). Default `true`. `false` = only - * `IAPL_NOINDEX=1` makes a site noindex, as before 1.17.0. `IAPL_NOINDEX=0` switches it off for one - * environment. - */ - developmentNoindex?: boolean - /** * GET /api/ipal/doctor — read-only counts for `iapl-doctor --url` (users without 2FA, cookies * waiting for approval, versions). Answers 404 until IAPL_DOCTOR_TOKEN (≥ 32 characters) is set; diff --git a/test/indexNow.test.ts b/test/indexNow.test.ts index d88244b..5a64746 100644 --- a/test/indexNow.test.ts +++ b/test/indexNow.test.ts @@ -75,16 +75,6 @@ describe('IndexNow hook', () => { expect(fetchSpy).not.toHaveBeenCalled() }) - test('a development host sends nothing, with no variable; IAPL_NOINDEX=0 says otherwise', async () => { - vi.stubEnv('IAPL_NOINDEX', '') - vi.stubEnv('NEXT_PUBLIC_SERVER_URL', 'https://acme.dev.netscale.pl') - await run({ _status: 'published' }) - expect(fetchSpy).not.toHaveBeenCalled() - vi.stubEnv('IAPL_NOINDEX', '0') - await run({ _status: 'published' }) - expect(fetchSpy).toHaveBeenCalledOnce() - }) - test('staging copy (IAPL_NOINDEX) sends nothing even in production', async () => { vi.stubEnv('IAPL_NOINDEX', '1') await run({ _status: 'published' }) diff --git a/test/mailRelay.test.ts b/test/mailRelay.test.ts index fc8bd00..22e382d 100644 --- a/test/mailRelay.test.ts +++ b/test/mailRelay.test.ts @@ -877,10 +877,6 @@ describe('the token over time', () => { // …and mail.relay.developmentHosts wins for the mail service expect(at('https://acme.dev.netscale.pl', own, { developmentHosts: ['acme.*'] })).toEqual({ by: 'development-host', pattern: 'acme.*' }) expect(at('https://acme.dev.netscale.pl', undefined, { developmentHosts: [] })).toBeNull() - // (that a development host is also kept out of search engines is not the mail service's signal: only the variable is) - vi.stubEnv('NEXT_PUBLIC_SERVER_URL', 'https://acme.dev.netscale.pl') - expect(at('https://acme.dev.netscale.pl', undefined, { developmentHosts: [] })).toBeNull() - vi.stubEnv('NEXT_PUBLIC_SERVER_URL', '') // either signal is enough; the host is named first vi.stubEnv('IAPL_NOINDEX', '1') expect(at('https://client.pl')).toEqual({ by: 'noindex' }) diff --git a/test/plugin.test.ts b/test/plugin.test.ts index cc43185..dd535e0 100644 --- a/test/plugin.test.ts +++ b/test/plugin.test.ts @@ -5,7 +5,6 @@ import { describe, expect, test, vi } from 'vitest' import type { I18nConfig } from '../src/modules/i18n/types.js' import { pluginDevelopmentHosts } from '../src/modules/email/relay/options.js' -import { noindexDevelopmentHosts } from '../src/modules/shared/developmentHosts.js' import { iapl } from '../src/plugin.js' import { withTotpParts } from './helpers.js' @@ -32,12 +31,6 @@ describe('iapl — config transform', () => { expect(await hosts()).toEqual(['*.dev.netscale.pl']) expect(await hosts(['*.preview.agency-example.com'])).toEqual(['*.preview.agency-example.com']) expect(await hosts([])).toEqual([]) - // the same options reach the helpers that have no config at hand (robots, metadata, IndexNow) - expect(noindexDevelopmentHosts()).toEqual([]) - await iapl({ access: { authCollection: 'users' }, developmentNoindex: false, i18n, twoFactor: false })(base()) - expect(noindexDevelopmentHosts()).toBe(false) - await iapl({ access: { authCollection: 'users' }, i18n, twoFactor: false })(base()) - expect(noindexDevelopmentHosts()).toEqual(['*.dev.netscale.pl']) }) test('adds globals, endpoint, localization and roles', async () => { diff --git a/test/seo.test.ts b/test/seo.test.ts index b20e522..b6b30d5 100644 --- a/test/seo.test.ts +++ b/test/seo.test.ts @@ -264,82 +264,6 @@ describe('site-wide noindex (IAPL_NOINDEX) and Markdown headers', () => { }) }) -describe('a development host is noindex without IAPL_NOINDEX (iapl({ developmentHosts, developmentNoindex }))', () => { - const DISALLOW_ALL = { rules: { disallow: ['/'], userAgent: '*' } } - const tag = (args?: Parameters[0]) => buildSecurityHeaders(args).find((h) => h.key === 'X-Robots-Tag')?.value - const load = async () => ({ - ...(await import('../src/modules/seo/buildMetadata.js')), - ...(await import('../src/modules/seo/siteNoindex.js')), - ...(await import('../src/modules/shared/developmentHosts.js')), - vi: (await import('vitest')).vi, - }) - const DEV = 'https://acme.dev.netscale.pl' - - test('robots, the page meta and the header on the built-in development domain, with no variable; the real domain is untouched', async () => { - const { buildMetadata, configureDevelopmentHosts, isSiteNoindex, siteNoindexSignal, vi } = await load() - configureDevelopmentHosts() - vi.stubEnv('IAPL_NOINDEX', '') - vi.stubEnv('IPAL_NOINDEX', '') - try { - expect(buildRobots({ baseUrl: DEV })).toEqual(DISALLOW_ALL) - expect(buildRobots({ baseUrl: 'https://acme.pl' })).not.toEqual(DISALLOW_ALL) - expect(buildMetadata({ baseUrl: DEV, config, locale: 'pl', slugs: { pl: 'x' } }).robots).toEqual({ follow: false, index: false }) - expect(buildMetadata({ baseUrl: 'https://acme.pl', config, locale: 'pl', slugs: { pl: 'x' } }).robots).toMatchObject({ index: true }) - expect(tag({ serverUrl: DEV })).toBe('noindex, nofollow') - expect(tag({ serverUrl: 'https://acme.pl' })).toBeUndefined() - expect(siteNoindexSignal({ host: DEV })).toBe('development-host') - // helpers that are given no address read NEXT_PUBLIC_SERVER_URL - vi.stubEnv('NEXT_PUBLIC_SERVER_URL', DEV) - expect(tag()).toBe('noindex, nofollow') - expect(isSiteNoindex()).toBe(true) - expect(buildMetadata({ config, locale: 'pl', slugs: { pl: 'x' } }).robots).toEqual({ follow: false, index: false }) - vi.stubEnv('NEXT_PUBLIC_SERVER_URL', 'https://acme.pl') - expect(tag()).toBeUndefined() - expect(isSiteNoindex()).toBe(false) - } finally { - vi.unstubAllEnvs() - } - }) - - test('the switches: IAPL_NOINDEX=0 for one environment, developmentNoindex: false, another list, an empty list', async () => { - const { configureDevelopmentHosts, isSiteNoindex, noindexDevelopmentHosts, siteNoindexSignal, vi } = await load() - vi.stubEnv('IAPL_NOINDEX', '') - vi.stubEnv('IPAL_NOINDEX', '') - try { - configureDevelopmentHosts() - for (const off of ['0', 'false', 'no', 'OFF']) { - vi.stubEnv('IAPL_NOINDEX', off) - expect(buildRobots({ baseUrl: DEV })).not.toEqual(DISALLOW_ALL) - expect(tag({ serverUrl: DEV })).toBeUndefined() - } - vi.stubEnv('IAPL_NOINDEX', '1') // the variable still works everywhere - expect(siteNoindexSignal({ host: 'https://acme.pl' })).toBe('env') - vi.stubEnv('IAPL_NOINDEX', 'maybe') // says nothing: the host decides - expect(isSiteNoindex({ host: DEV })).toBe(true) - vi.stubEnv('IAPL_NOINDEX', '') - - configureDevelopmentHosts({ noindex: false }) // iapl({ developmentNoindex: false }) - expect(noindexDevelopmentHosts()).toBe(false) - expect(buildRobots({ baseUrl: DEV })).not.toEqual(DISALLOW_ALL) - expect(isSiteNoindex({ host: DEV })).toBe(false) - - configureDevelopmentHosts({ hosts: ['*.preview.agency-example.com'] }) // iapl({ developmentHosts: [...] }) - expect(buildRobots({ baseUrl: 'https://x.preview.agency-example.com' })).toEqual(DISALLOW_ALL) - expect(buildRobots({ baseUrl: DEV })).not.toEqual(DISALLOW_ALL) - configureDevelopmentHosts({ hosts: [] }) - expect(isSiteNoindex({ host: DEV })).toBe(false) - - // next.config runs before the plugin: the header builder takes the list itself - expect(tag({ developmentHosts: ['*.preview.agency-example.com'], serverUrl: 'https://x.preview.agency-example.com' })).toBe('noindex, nofollow') - expect(tag({ developmentHosts: false, serverUrl: DEV })).toBeUndefined() - expect(tag({ developmentHosts: [], serverUrl: DEV })).toBeUndefined() - } finally { - configureDevelopmentHosts() - vi.unstubAllEnvs() - } - }) -}) - describe('createPageMetadata — siteDescription fallback', () => { // Regresja 1.10.0: readSiteMetaConfig czytał siteDescription, ale nie trafiał do buildMetadata — // strona bez meta.description nie miała (Lighthouse SEO).