Revert "A development host is kept out of search engines without IAPL_NOINDEX (developmentNoindex, default on)"
This reverts commit bc3aac249f.
This commit is contained in:
@@ -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<RelayOptions, 'developmentHosts' | 'host'>): 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)? */
|
||||
|
||||
@@ -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' })
|
||||
}
|
||||
|
||||
|
||||
@@ -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 } }
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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'
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user