A development host is kept out of search engines without IAPL_NOINDEX (developmentNoindex, default on)
Separate from the mail rule so that it can be taken or left. A site whose address matches
iapl({ developmentHosts }) - built in: *.dev.netscale.pl - is noindex with no env: robots.txt disallows
everything, pages carry noindex, IndexNow sends nothing, buildSecurityHeaders() adds X-Robots-Tag. Nothing
kept a development copy out of search engines until now unless somebody set the variable.
- iapl({ developmentNoindex: false }) switches it off for the project, IAPL_NOINDEX=0 for one environment
- buildSecurityHeaders({ developmentHosts, serverUrl }): next.config runs before the plugin
- the mail rule keeps its own two signals: the development pattern, and the variable itself
- changelog "what changes on upgrade", deployment.md, security.md, AGENT.md, skills
Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
co-authored by
Claude Fable 5.2
parent
14abf369da
commit
bc3aac249f
@@ -32,6 +32,15 @@ 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 |
|
||||
@@ -111,6 +120,8 @@ 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
|
||||
|
||||
+1
-1
@@ -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 |
|
||||
| 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://<dev host>/ \| grep -i x-robots-tag` and `/robots.txt` says `Disallow: /`; on the real domain neither |
|
||||
| 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 |
|
||||
|
||||
@@ -266,7 +266,7 @@ The plugin's own variables are `IAPL_<NAME>`; 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** | — (when set: robots Disallow, meta noindex, `X-Robots-Tag`, IndexNow sends nothing) | staging env |
|
||||
| `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 |
|
||||
| `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 |
|
||||
|
||||
|
||||
@@ -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 })` + `<SiteProviders nonce>`); `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). Search engines: `robots` instead of
|
||||
(`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
|
||||
`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`.
|
||||
|
||||
@@ -581,6 +581,11 @@ 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
|
||||
|
||||
+2
-2
@@ -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`) |
|
||||
| `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_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 | never on production |
|
||||
| `IAPL_NOINDEX` | — | ✅ staging only (a development host needs none) | 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
|
||||
|
||||
+1
-1
@@ -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), `X-Robots-Tag: noindex, nofollow` is added to every response.
|
||||
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.
|
||||
|
||||
**Uploads:** `buildUploadSecurityHeaders({ collections = ['media'] })` returns `headers()` rules for
|
||||
`/api/<collection>/file/*` (sandbox, no scripts) — an SVG from local disk cannot run a script on the site's
|
||||
|
||||
@@ -266,7 +266,7 @@ The plugin's own variables are `IAPL_<NAME>`; 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** | — (when set: robots Disallow, meta noindex, `X-Robots-Tag`, IndexNow sends nothing) | staging env |
|
||||
| `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 |
|
||||
| `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 |
|
||||
|
||||
|
||||
@@ -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 })` + `<SiteProviders nonce>`); `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). Search engines: `robots` instead of
|
||||
(`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
|
||||
`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`.
|
||||
|
||||
@@ -581,6 +581,11 @@ 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
|
||||
|
||||
@@ -5,7 +5,7 @@ import { randomBytes } from 'node:crypto'
|
||||
import type { RelayOptions, ResolvedRelayOptions } from './options.js'
|
||||
|
||||
import { PLUGIN_VERSION } from '../../../version.js'
|
||||
import { isSiteNoindex } from '../../seo/siteNoindex.js'
|
||||
import { noindexEnv } 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,7 +108,8 @@ export type NonPublicSignal = { by: 'development-host'; pattern: string } | { by
|
||||
export function siteNonPublicSignal(payload: BasePayload, options: Pick<RelayOptions, 'developmentHosts' | 'host'>): NonPublicSignal | null {
|
||||
const pattern = matchDevelopmentHost(relayHost(payload, options), options.developmentHosts ?? pluginDevelopmentHosts(payload))
|
||||
if (pattern) {return { by: 'development-host', pattern }}
|
||||
return isSiteNoindex() ? { by: 'noindex' } : null
|
||||
// the variable itself: whether a development host is ALSO kept out of search engines is another question
|
||||
return noindexEnv() === true ? { by: 'noindex' } : null
|
||||
}
|
||||
|
||||
/** Is this site a non-public copy (`siteNonPublicSignal` as a yes or no)? */
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
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'
|
||||
|
||||
/**
|
||||
@@ -29,6 +30,14 @@ 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
|
||||
@@ -56,6 +65,8 @@ 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
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,7 +104,9 @@ 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[] = []
|
||||
|
||||
@@ -124,8 +137,8 @@ export function buildSecurityHeaders(args: BuildSecurityHeadersArgs = {}): Secur
|
||||
headers.push({ key: 'Cross-Origin-Opener-Policy', value: coop })
|
||||
}
|
||||
|
||||
// Staging / preview (IAPL_NOINDEX=1): keep every response out of search engines.
|
||||
if (isSiteNoindex()) {
|
||||
// Staging / preview (IAPL_NOINDEX=1) or a development host: keep every response out of search engines.
|
||||
if (isSiteNoindex({ developmentHosts, host: serverUrl })) {
|
||||
headers.push({ key: 'X-Robots-Tag', value: 'noindex, nofollow' })
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
...(isSiteNoindex({ host: origin })
|
||||
? { robots: { follow: false, index: false } }
|
||||
: noindex || meta?.noindex
|
||||
? { robots: { follow: true, index: false } }
|
||||
|
||||
@@ -140,8 +140,8 @@ export function buildRobots({
|
||||
sitemap = true,
|
||||
}: BuildRobotsArgs): RobotsRules {
|
||||
const origin = baseUrl.replace(/\/$/, '')
|
||||
// Staging / preview (IAPL_NOINDEX=1): nothing may be crawled.
|
||||
if (isSiteNoindex()) {return { rules: { disallow: ['/'], userAgent: '*' } }}
|
||||
// Staging / preview (IAPL_NOINDEX=1) or a development host (iapl({ developmentHosts })): nothing may be crawled.
|
||||
if (isSiteNoindex({ host: origin })) {return { rules: { disallow: ['/'], userAgent: '*' } }}
|
||||
|
||||
const defaults = [...(adminRoute ? [adminRoute] : []), '/api']
|
||||
const paramRules = disallowParams
|
||||
|
||||
@@ -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()) {return null}
|
||||
if (isSiteNoindex({ host: origin })) {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
|
||||
|
||||
@@ -1,19 +1,49 @@
|
||||
import { isDevelopmentHost, noindexDevelopmentHosts } from '../shared/developmentHosts.js'
|
||||
import { readEnv } from '../shared/envName.js'
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* 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.
|
||||
*/
|
||||
/** 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'
|
||||
|
||||
export function isSiteNoindex(): boolean {
|
||||
/** What the variable says: `true` (1 / true / yes), `false` (0 / false / no / off), or `undefined` when it says nothing. */
|
||||
export function noindexEnv(): boolean | undefined {
|
||||
const v = readEnv(IAPL_SITE_NOINDEX_ENV)?.trim().toLowerCase()
|
||||
return v === '1' || v === 'true' || v === 'yes'
|
||||
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
|
||||
}
|
||||
|
||||
@@ -42,3 +42,21 @@ 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)
|
||||
}
|
||||
|
||||
@@ -66,6 +66,7 @@ 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'
|
||||
|
||||
@@ -752,6 +753,7 @@ 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 = {
|
||||
|
||||
@@ -145,6 +145,15 @@ 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;
|
||||
|
||||
@@ -75,6 +75,16 @@ 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' })
|
||||
|
||||
@@ -877,6 +877,10 @@ 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' })
|
||||
|
||||
@@ -5,6 +5,7 @@ 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'
|
||||
|
||||
@@ -31,6 +32,12 @@ 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 () => {
|
||||
|
||||
@@ -264,6 +264,82 @@ 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<typeof buildSecurityHeaders>[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 <meta name="description"> (Lighthouse SEO).
|
||||
|
||||
Reference in New Issue
Block a user