@zero2webmaster/starter-kit 0.5.8 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/index.d.ts +28 -1
- package/dist/index.js +1 -1
- package/dist/scaffolders/common.js +5 -0
- package/dist/scaffolders/nextjs.d.ts +1 -1
- package/dist/scaffolders/nextjs.js +433 -41
- package/dist/standards.d.ts +1 -1
- package/dist/standards.js +14 -4
- package/dist/writer.js +12 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# z2w-starter-kit
|
|
2
2
|
|
|
3
|
-
**Version:** 0.
|
|
3
|
+
**Version:** 0.7.0 | **Framework:** 2.13.0
|
|
4
4
|
|
|
5
5
|
> Node CLI to scaffold new Z2W projects from canonical Templates + AGENTS.md.
|
|
6
6
|
|
|
@@ -99,4 +99,4 @@ For licensing inquiries: kerry@zero2webmaster.com.
|
|
|
99
99
|
---
|
|
100
100
|
|
|
101
101
|
*Scaffolded 2026-05-28 via the [[instantiate-z2w-project]] Claude Code skill v1; reconciled against the consolidated skill v1.1.0 (brief-first + Agent Coordination block) on 2026-05-29.*
|
|
102
|
-
*Version: 0.
|
|
102
|
+
*Version: 0.7.0 | Last Updated: 2026-07-30*
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { writeScaffold } from "./writer.js";
|
|
2
2
|
import type { ScaffoldFile } from "./scaffolders/common.js";
|
|
3
3
|
import type { StandardDecision } from "./standards.js";
|
|
4
|
-
export declare const version = "0.
|
|
4
|
+
export declare const version = "0.6.0";
|
|
5
5
|
export type ProjectType = "wp-plugin" | "cf-worker" | "cf-pages" | "nextjs" | "python-service" | "node-service" | "library" | "protocol-repo";
|
|
6
6
|
export type BrandPreset = "save-the-frogs" | "bansuri-bliss" | "zero2webmaster" | "custom";
|
|
7
7
|
export type DbStrategy = "none" | "neon-postgres" | "supabase" | "sqlite" | "mysql-wp" | "other";
|
|
@@ -112,6 +112,33 @@ export interface ScaffoldInputs {
|
|
|
112
112
|
* failed silently" surface.
|
|
113
113
|
*/
|
|
114
114
|
hasObservability?: boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Whether the incoming `Host` header selects the tenant — a HOST-ROUTED
|
|
117
|
+
* multi-tenant app, where each tenant has its own front door (its own custom
|
|
118
|
+
* domain) served by one deployment. True for `org-hq`, `site-control`,
|
|
119
|
+
* `z2w-member-match`; false for a single-tenant app that has exactly one
|
|
120
|
+
* canonical domain.
|
|
121
|
+
*
|
|
122
|
+
* When `true`, the `nextjs` scaffolder changes two things:
|
|
123
|
+
*
|
|
124
|
+
* 1. **`next.config.mjs` omits the `*.vercel.app` → custom-domain alias
|
|
125
|
+
* redirect.** That redirect assumes ONE canonical destination, which is
|
|
126
|
+
* precisely what a host-routed app does not have — redirecting an alias to a
|
|
127
|
+
* fixed host drops visitors into some other tenant's app.
|
|
128
|
+
* 2. **A `middleware.ts` host guard is emitted instead**, which returns **404**
|
|
129
|
+
* for a production request on a known-non-canonical host. Per the 2026-07-30
|
|
130
|
+
* ruling (reached across `org-hq`, `site-control` and `z2w-member-match`):
|
|
131
|
+
* **404 on an unmapped Host, never a redirect to a fixed one.**
|
|
132
|
+
*
|
|
133
|
+
* It also emits the `CANONICAL_HOSTS` allowlist stub in `.env.example`, since a
|
|
134
|
+
* Host-routed app needs to know which hosts are legitimately its own.
|
|
135
|
+
*
|
|
136
|
+
* Optional and defaults to `false` (single-tenant — the alias redirect ships as
|
|
137
|
+
* before). Honored only by the `nextjs` type; other types have no Host-based
|
|
138
|
+
* routing surface. Deliberately opt-in on the `--input` / programmatic paths so
|
|
139
|
+
* an existing caller's output is unchanged.
|
|
140
|
+
*/
|
|
141
|
+
hostRoutedTenancy?: boolean;
|
|
115
142
|
/** Present only when `brand === "custom"`. */
|
|
116
143
|
customBrand?: CustomBrandInputs;
|
|
117
144
|
/**
|
package/dist/index.js
CHANGED
|
@@ -21,7 +21,7 @@ import * as path from "node:path";
|
|
|
21
21
|
import { Writable } from "node:stream";
|
|
22
22
|
import { isValidSlug } from "./parse-brief.js";
|
|
23
23
|
import { writeScaffold } from "./writer.js";
|
|
24
|
-
export const version = "0.
|
|
24
|
+
export const version = "0.6.0";
|
|
25
25
|
// Canonical enum value-arrays. These live here, next to the type unions they
|
|
26
26
|
// enumerate, so both the CLI's confirm/wizard flows (which re-export them) and
|
|
27
27
|
// the programmatic `validateScaffoldInputs` share one source of truth. Keep
|
|
@@ -900,6 +900,11 @@ out/
|
|
|
900
900
|
.env
|
|
901
901
|
.env.local
|
|
902
902
|
.env*.local
|
|
903
|
+
# Vercel CLI local state. .vercel/project.json pins this checkout to ONE Vercel
|
|
904
|
+
# project id, so a committed copy makes a fork or a staging project silently
|
|
905
|
+
# deploy to the original. Note \`vercel link\` appends a bare \`.vercel\` line
|
|
906
|
+
# itself — if you see a duplicate, that is where it came from.
|
|
907
|
+
.vercel/
|
|
903
908
|
`,
|
|
904
909
|
"python-service": `.DS_Store
|
|
905
910
|
__pycache__/
|
|
@@ -6,4 +6,4 @@ export declare function scaffoldNextjs(inputs: ScaffoldInputs, opts?: Scaffolder
|
|
|
6
6
|
* they can assert / require the canonical SEO baseline file list without
|
|
7
7
|
* hardcoding the paths in two places.
|
|
8
8
|
*/
|
|
9
|
-
export declare const NEXTJS_SEO_BASELINE_PATHS: readonly ["app/layout.tsx", "app/page.tsx", "app/sitemap.ts", "app/robots.ts", "app/opengraph-image.tsx", "lib/analytics/utm.ts", "lib/analytics/Analytics.tsx", "lib/analytics/RouteTracker.tsx", "SEO-CHECKLIST.md", ".env.example"];
|
|
9
|
+
export declare const NEXTJS_SEO_BASELINE_PATHS: readonly ["app/layout.tsx", "app/page.tsx", "app/sitemap.ts", "app/robots.ts", "lib/seo/canonical-host.mjs", "lib/seo/page-metadata.ts", "app/opengraph-image.tsx", "lib/analytics/utm.ts", "lib/analytics/Analytics.tsx", "lib/analytics/RouteTracker.tsx", "SEO-CHECKLIST.md", ".env.example"];
|
|
@@ -6,13 +6,22 @@
|
|
|
6
6
|
// 1. SSR/SSG — App Router pages are server-rendered by default.
|
|
7
7
|
// 2. Per-page metadata — root `metadata` in app/layout.tsx + per-page
|
|
8
8
|
// `metadata` in app/page.tsx with unique title, description, OG, Twitter.
|
|
9
|
+
// Built by the `pageMetadata()` helper in lib/seo/page-metadata.ts, because
|
|
10
|
+
// Next.js merges metadata SHALLOWLY per top-level key: a hand-written
|
|
11
|
+
// `openGraph: { title, description }` REPLACES the layout's whole openGraph
|
|
12
|
+
// object and silently deletes og:type / og:site_name, and the matching
|
|
13
|
+
// `twitter: {}` downgrades the card to a small square.
|
|
9
14
|
// 3. Exactly one <h1> per page + semantic HTML — app/page.tsx wires it.
|
|
10
15
|
// 4. Image alt text — the page template uses next/image with `alt=""` /
|
|
11
16
|
// descriptive alt where appropriate (placeholder content uses semantic
|
|
12
17
|
// HTML; no decorative images at scaffold time).
|
|
13
18
|
// 5. JSON-LD — `Organization` schema injected in app/layout.tsx.
|
|
14
|
-
// 6. sitemap.xml + robots.txt — app/sitemap.ts + app/robots.ts
|
|
15
|
-
//
|
|
19
|
+
// 6. sitemap.xml + robots.txt — app/sitemap.ts + app/robots.ts. Indexable
|
|
20
|
+
// requires BOTH `VERCEL_ENV === 'production'` AND a real canonical domain
|
|
21
|
+
// (not the *.example.com placeholder, not *.vercel.app) — gating on
|
|
22
|
+
// VERCEL_ENV alone published `Allow: /` with placeholder sitemap URLs on the
|
|
23
|
+
// first prod deploy. Predicate lives in lib/seo/canonical-host.mjs, shared
|
|
24
|
+
// with next.config.mjs so robots and the alias redirect cannot disagree.
|
|
16
25
|
// 7. Fathom — the three-file pattern under lib/analytics/ (utm.ts +
|
|
17
26
|
// Analytics.tsx + RouteTracker.tsx), mounted as <Analytics /> in
|
|
18
27
|
// app/layout.tsx, gated on `NEXT_PUBLIC_FATHOM_SITE_ID` (per
|
|
@@ -25,6 +34,18 @@
|
|
|
25
34
|
// next.config.mjs that redirects the production *.vercel.app alias to the
|
|
26
35
|
// custom domain (SEO-duplicate fix — Z2W heads-up 2026-06-29; self-disabling
|
|
27
36
|
// until NEXT_PUBLIC_SITE_URL is a real custom domain).
|
|
37
|
+
//
|
|
38
|
+
// Conditional on `hostRoutedTenancy` (a HOST-ROUTED multi-tenant app, where the
|
|
39
|
+
// Host selects the tenant): the single-destination alias redirect is OMITTED —
|
|
40
|
+
// wrong shape, there is no one canonical domain — and a `middleware.ts` host
|
|
41
|
+
// guard is emitted that returns **404** on a known-non-canonical production host.
|
|
42
|
+
// Ruling 2026-07-30 across org-hq / site-control / z2w-member-match: 404 on an
|
|
43
|
+
// unmapped Host, never a redirect to a fixed one.
|
|
44
|
+
//
|
|
45
|
+
// Conditional on `sendsEmail` or `hostRoutedTenancy`: a `CANONICAL_HOSTS`
|
|
46
|
+
// allowlist stub in `.env.example`. This CLI emits no auth code, so it plants the
|
|
47
|
+
// seam + the pointer at [[z2w-magic-link-auth]] §0 rule 2b rather than a check —
|
|
48
|
+
// see CANONICAL_HOSTS_ENV_BLOCK for why that is the honest half.
|
|
28
49
|
import { commonBaseFiles, EMAIL_DEPS, EMAIL_ENV_BLOCK, emailFiles, localEnvFrom, resolveBrandSpec, sub, } from "./common.js";
|
|
29
50
|
const NARRATIVE = `## What this is
|
|
30
51
|
|
|
@@ -43,9 +64,11 @@ npm run build && npm start # production build
|
|
|
43
64
|
|
|
44
65
|
- \`app/layout.tsx\` — root \`metadata\` with \`title.template\`, \`title.default\`, \`description\`, \`openGraph\`, \`twitter\`, \`metadataBase\`; mounts \`<Analytics />\`; JSON-LD Organization schema.
|
|
45
66
|
- \`app/page.tsx\` — per-page \`metadata\` (unique title + description; never inherit defaults); exactly one \`<h1>\`; semantic HTML.
|
|
67
|
+
- \`lib/seo/page-metadata.ts\` — \`pageMetadata()\`, the ONE builder for every page's \`metadata\`. **Use it for every new page.** Next.js merges metadata shallowly per top-level key, so a hand-written partial \`openGraph\` replaces the layout's whole object and silently drops \`og:type\` / \`og:site_name\`, and a partial \`twitter\` downgrades the card to a small square.
|
|
46
68
|
- \`lib/analytics/{utm.ts,Analytics.tsx,RouteTracker.tsx}\` — Fathom (per [[fathom-analytics]]); the RouteTracker fires \`trackPageview()\` on route change + captures first-touch UTM. Gated on \`NEXT_PUBLIC_FATHOM_SITE_ID\`.
|
|
47
|
-
- \`app/sitemap.ts\` — sitemap generator; lists indexable pages.
|
|
48
|
-
- \`app/robots.ts\` — robots generator
|
|
69
|
+
- \`app/sitemap.ts\` — sitemap generator; lists indexable pages. \`lastModified\` is deliberately omitted until you have a real content timestamp.
|
|
70
|
+
- \`app/robots.ts\` — robots generator. Indexable requires BOTH a production deployment AND a real canonical domain in \`NEXT_PUBLIC_SITE_URL\`; anything else emits \`Disallow: /\`. **Both files are prerendered at build time, so changing \`NEXT_PUBLIC_SITE_URL\` needs a redeploy.**
|
|
71
|
+
- \`lib/seo/canonical-host.mjs\` — the one canonical-host predicate, shared by \`app/robots.ts\` and \`next.config.mjs\` so the indexability gate and the alias redirect cannot disagree.
|
|
49
72
|
- \`app/opengraph-image.tsx\` — default OG image (replace placeholder before launch).
|
|
50
73
|
- \`SEO-CHECKLIST.md\` — per-page checklist; consult before adding new pages.
|
|
51
74
|
|
|
@@ -80,8 +103,76 @@ const PACKAGE_JSON_TEMPLATE = `{
|
|
|
80
103
|
"homepage": "https://github.com/{{github_org}}/{{slug}}"
|
|
81
104
|
}
|
|
82
105
|
`;
|
|
106
|
+
/**
|
|
107
|
+
* ONE definition of "is this host a real canonical domain?", shared by
|
|
108
|
+
* `next.config.mjs` (the alias redirect) and `app/robots.ts` (the indexability
|
|
109
|
+
* gate). Emitted as `.mjs` on purpose: `next.config.mjs` is plain ESM loaded
|
|
110
|
+
* before any TypeScript exists, so it cannot import a `.ts` module — while the
|
|
111
|
+
* scaffolded `tsconfig.json` sets `allowJs: true`, so `app/robots.ts`
|
|
112
|
+
* type-checks this same file and picks up its JSDoc types. Two copies would let
|
|
113
|
+
* robots.txt say "index me" while the alias redirect is off — the single most
|
|
114
|
+
* invisible drift available in this file family (`site-control`, 2026-07-29).
|
|
115
|
+
*/
|
|
116
|
+
const CANONICAL_HOST_MODULE_TEMPLATE = `// Shared canonical-host predicate. Imported by BOTH next.config.mjs (alias
|
|
117
|
+
// redirect) and app/robots.ts (indexability gate) so the two can never disagree.
|
|
118
|
+
//
|
|
119
|
+
// Emitted as .mjs deliberately: next.config.mjs is plain ESM loaded before any
|
|
120
|
+
// TypeScript exists and cannot import a .ts module. tsconfig.json sets
|
|
121
|
+
// \`allowJs: true\`, so app/robots.ts type-checks this file too.
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Host suffixes that are NEVER a canonical domain.
|
|
125
|
+
*
|
|
126
|
+
* \`.vercel.app\` is in here for consistency, not as an extra rule: the alias
|
|
127
|
+
* redirect in next.config.mjs already 301s every production *.vercel.app host to
|
|
128
|
+
* the custom domain precisely so they are not crawled as duplicates. Treating one
|
|
129
|
+
* as canonical would contradict a redirect this project already ships.
|
|
130
|
+
*
|
|
131
|
+
* \`.example.com\` is the scaffold's own placeholder default, which is by
|
|
132
|
+
* definition what NEXT_PUBLIC_SITE_URL holds on day one.
|
|
133
|
+
*/
|
|
134
|
+
export const NON_CANONICAL_HOST_SUFFIXES = [".vercel.app", ".example.com"];
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* The canonical host from a site URL, or "" when there isn't one yet.
|
|
138
|
+
*
|
|
139
|
+
* @param {string | undefined} rawSiteUrl typically process.env.NEXT_PUBLIC_SITE_URL
|
|
140
|
+
* @returns {string} a real custom-domain host, else ""
|
|
141
|
+
*/
|
|
142
|
+
export function canonicalHost(rawSiteUrl) {
|
|
143
|
+
try {
|
|
144
|
+
const { host } = new URL(rawSiteUrl || "");
|
|
145
|
+
// "localhost:3000" (no scheme) parses with an EMPTY host rather than throwing.
|
|
146
|
+
if (!host) return "";
|
|
147
|
+
return NON_CANONICAL_HOST_SUFFIXES.some((s) => host.endsWith(s)) ? "" : host;
|
|
148
|
+
} catch {
|
|
149
|
+
// Not a valid absolute URL yet (blank, or a bare hostname).
|
|
150
|
+
return "";
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Whether this deployment may be indexed by search engines.
|
|
156
|
+
*
|
|
157
|
+
* Requires BOTH a production deployment AND a real canonical domain. Gating on
|
|
158
|
+
* VERCEL_ENV alone means the FIRST production deploy publishes \`Allow: /\` plus a
|
|
159
|
+
* sitemap of placeholder URLs, because NEXT_PUBLIC_SITE_URL is unset on day one
|
|
160
|
+
* and the fallback is a domain this project does not own. Getting placeholder
|
|
161
|
+
* URLs back out of a search index is slow and awkward, so this fails toward the
|
|
162
|
+
* visible error: a misconfigured deploy stays \`Disallow: /\`, which one \`curl\`
|
|
163
|
+
* reveals and one env var fixes.
|
|
164
|
+
*
|
|
165
|
+
* @param {Record<string, string | undefined>} [env] defaults to process.env
|
|
166
|
+
* @returns {boolean}
|
|
167
|
+
*/
|
|
168
|
+
export function isIndexableDeployment(env = process.env) {
|
|
169
|
+
return env.VERCEL_ENV === "production" && canonicalHost(env.NEXT_PUBLIC_SITE_URL) !== "";
|
|
170
|
+
}
|
|
171
|
+
`;
|
|
83
172
|
const NEXT_CONFIG_TEMPLATE = `/** @type {import('next').NextConfig} */
|
|
84
173
|
|
|
174
|
+
import { canonicalHost } from "./lib/seo/canonical-host.mjs";
|
|
175
|
+
|
|
85
176
|
// SEO: redirect EVERY auto-assigned PRODUCTION *.vercel.app alias to the custom
|
|
86
177
|
// domain so none is crawled as an indexable duplicate of the whole site
|
|
87
178
|
// (Z2W standing heads-up 2026-06-29; recipe = [[portable-stack]] §24).
|
|
@@ -101,25 +192,15 @@ const NEXT_CONFIG_TEMPLATE = `/** @type {import('next').NextConfig} */
|
|
|
101
192
|
// While it is blank, the *.example.com placeholder, or itself a *.vercel.app
|
|
102
193
|
// host, the redirect list is empty — so a fresh scaffold never self-redirects,
|
|
103
194
|
// and the custom domain (not *.vercel.app) never matches the regex → no loop.
|
|
195
|
+
//
|
|
196
|
+
// \`canonicalHost\` is imported rather than defined here so app/robots.ts decides
|
|
197
|
+
// indexability from the SAME predicate. See lib/seo/canonical-host.mjs.
|
|
104
198
|
const isVercelProduction = process.env.VERCEL_ENV === "production";
|
|
105
199
|
|
|
106
|
-
function canonicalHost() {
|
|
107
|
-
const raw = process.env.NEXT_PUBLIC_SITE_URL || "";
|
|
108
|
-
try {
|
|
109
|
-
const host = new URL(raw).host;
|
|
110
|
-
if (host && !host.endsWith(".vercel.app") && !host.endsWith(".example.com")) {
|
|
111
|
-
return host;
|
|
112
|
-
}
|
|
113
|
-
} catch {
|
|
114
|
-
// NEXT_PUBLIC_SITE_URL not a valid absolute URL yet — no redirect.
|
|
115
|
-
}
|
|
116
|
-
return "";
|
|
117
|
-
}
|
|
118
|
-
|
|
119
200
|
const nextConfig = {
|
|
120
201
|
reactStrictMode: true,
|
|
121
202
|
async redirects() {
|
|
122
|
-
const host = canonicalHost();
|
|
203
|
+
const host = canonicalHost(process.env.NEXT_PUBLIC_SITE_URL);
|
|
123
204
|
// Only in production, and only once a real custom domain is configured.
|
|
124
205
|
if (!host || !isVercelProduction) return [];
|
|
125
206
|
return [
|
|
@@ -136,6 +217,213 @@ const nextConfig = {
|
|
|
136
217
|
|
|
137
218
|
export default nextConfig;
|
|
138
219
|
`;
|
|
220
|
+
/**
|
|
221
|
+
* The `next.config.mjs` variant for a HOST-ROUTED multi-tenant app, where the
|
|
222
|
+
* incoming Host selects the tenant. Emitted when `hostRoutedTenancy` is set.
|
|
223
|
+
*
|
|
224
|
+
* The single-destination alias redirect above is wrong for this shape: there is
|
|
225
|
+
* no one canonical domain to redirect to — every tenant has its own front door,
|
|
226
|
+
* so redirecting a `*.vercel.app` alias to a fixed host lands visitors in some
|
|
227
|
+
* other tenant's app. The ruling (2026-07-30, three projects deep: `org-hq`,
|
|
228
|
+
* `site-control`, `z2w-member-match`) is **404 on an unmapped Host**, never a
|
|
229
|
+
* redirect to a fixed one. The redirect is therefore omitted here and the guard
|
|
230
|
+
* lives in `middleware.ts`.
|
|
231
|
+
*/
|
|
232
|
+
const NEXT_CONFIG_HOST_ROUTED_TEMPLATE = `/** @type {import('next').NextConfig} */
|
|
233
|
+
|
|
234
|
+
// HOST-ROUTED MULTI-TENANT APP — the incoming Host selects the tenant.
|
|
235
|
+
//
|
|
236
|
+
// NOTE the deliberate ABSENCE of the *.vercel.app → custom-domain alias redirect
|
|
237
|
+
// that single-tenant Z2W Next.js apps ship. That redirect assumes ONE canonical
|
|
238
|
+
// destination, which is exactly what this shape does not have: every tenant has
|
|
239
|
+
// its own front door, so redirecting an alias to a fixed host would drop visitors
|
|
240
|
+
// into some other tenant's app. The ruling is **404 on an unmapped Host, never a
|
|
241
|
+
// redirect to a fixed one** — enforced in middleware.ts, which is the only place
|
|
242
|
+
// that sees the request Host at runtime. See lib/seo/canonical-host.mjs.
|
|
243
|
+
|
|
244
|
+
const nextConfig = {
|
|
245
|
+
reactStrictMode: true,
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
export default nextConfig;
|
|
249
|
+
`;
|
|
250
|
+
/**
|
|
251
|
+
* The Host guard for a host-routed multi-tenant app: a production request
|
|
252
|
+
* arriving on a known-non-canonical host maps to no tenant, so it 404s.
|
|
253
|
+
*
|
|
254
|
+
* Scope is deliberately narrow — middleware cannot resolve tenant vanity domains
|
|
255
|
+
* without a DB read (which would burn Neon CU-hours on every request, per
|
|
256
|
+
* [[neon-postgres]]), so this rejects only the host classes the scaffold KNOWS
|
|
257
|
+
* are nobody's tenant. Resolving real tenant domains stays the app's job.
|
|
258
|
+
*/
|
|
259
|
+
const MIDDLEWARE_HOST_GUARD_TEMPLATE = `// Host guard for this HOST-ROUTED multi-tenant app.
|
|
260
|
+
//
|
|
261
|
+
// A production request arriving on a known-non-canonical host (*.vercel.app, the
|
|
262
|
+
// *.example.com placeholder) maps to NO tenant. Per the Z2W alias ruling it gets
|
|
263
|
+
// a 404 — never a redirect to a fixed canonical host, because there is no single
|
|
264
|
+
// canonical host in a host-routed app and redirecting would drop the visitor into
|
|
265
|
+
// a different tenant's front door.
|
|
266
|
+
//
|
|
267
|
+
// Deliberately narrow: this does NOT resolve tenant vanity domains, because that
|
|
268
|
+
// needs a DB read on every request and would burn Neon's CU-hour quota
|
|
269
|
+
// ([[neon-postgres]]). It rejects only the host classes that are nobody's tenant.
|
|
270
|
+
// Your tenant resolver still has to 404 a host it cannot map.
|
|
271
|
+
|
|
272
|
+
import { NextResponse } from "next/server";
|
|
273
|
+
import type { NextRequest } from "next/server";
|
|
274
|
+
import { NON_CANONICAL_HOST_SUFFIXES } from "@/lib/seo/canonical-host.mjs";
|
|
275
|
+
|
|
276
|
+
export function middleware(request: NextRequest) {
|
|
277
|
+
// Only in production. Preview deployments and localhost are *.vercel.app /
|
|
278
|
+
// localhost by nature, and blocking them would make every preview unusable.
|
|
279
|
+
if (process.env.VERCEL_ENV !== "production") return NextResponse.next();
|
|
280
|
+
|
|
281
|
+
const host = (request.headers.get("x-forwarded-host") ?? request.headers.get("host") ?? "")
|
|
282
|
+
.toLowerCase()
|
|
283
|
+
.split(":")[0];
|
|
284
|
+
|
|
285
|
+
if (NON_CANONICAL_HOST_SUFFIXES.some((suffix) => host.endsWith(suffix))) {
|
|
286
|
+
return new NextResponse(null, { status: 404 });
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
return NextResponse.next();
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export const config = {
|
|
293
|
+
// Skip Next internals and the health endpoint — an uptime monitor pointed at
|
|
294
|
+
// the platform alias must keep working ([[uptime-kuma-monitor]]).
|
|
295
|
+
matcher: ["/((?!_next/|api/health).*)"],
|
|
296
|
+
};
|
|
297
|
+
`;
|
|
298
|
+
/**
|
|
299
|
+
* The `pageMetadata()` helper — one builder for every page's `metadata` export.
|
|
300
|
+
*
|
|
301
|
+
* Exists because Next.js merges metadata SHALLOWLY, per TOP-LEVEL KEY. A page
|
|
302
|
+
* that sets `openGraph: { title, description }` does not extend the layout's
|
|
303
|
+
* openGraph — it REPLACES the whole object, deleting `og:type` and
|
|
304
|
+
* `og:site_name`; the matching `twitter: {}` deletes
|
|
305
|
+
* `card: "summary_large_image"` so a 1200x630 image renders as a small square.
|
|
306
|
+
* Nothing warns: `next build` is happy and the source reads as if it composes.
|
|
307
|
+
* (Reported by `site-control` 2026-07-29, who introduced it while FIXING the
|
|
308
|
+
* `<title>Home</title>` defect in this same file pair and caught it only by
|
|
309
|
+
* re-diffing served HTML.)
|
|
310
|
+
*
|
|
311
|
+
* Two design choices worth not "tidying" away:
|
|
312
|
+
*
|
|
313
|
+
* 1. `title: { absolute: ... }`. The layout's `title.template` reaches CHILD
|
|
314
|
+
* segments only, never app/page.tsx — the exact asymmetry behind the
|
|
315
|
+
* `<title>Home</title>` defect. `absolute` opts out of the template
|
|
316
|
+
* everywhere, so a page built by this helper renders the same title whether
|
|
317
|
+
* it lives at the root or six segments deep. One code path, verified once.
|
|
318
|
+
* The template stays in the layout for pages that don't use the helper.
|
|
319
|
+
* 2. `openGraph.url` is the PAGE path, not the site root. Next resolves it
|
|
320
|
+
* against `metadataBase`. The pre-helper layout hardcoded the site URL, so
|
|
321
|
+
* every page shared one og:url.
|
|
322
|
+
*/
|
|
323
|
+
const PAGE_METADATA_MODULE_TEMPLATE = `// Build EVERY page's \`metadata\` export with pageMetadata(). Do not hand-write
|
|
324
|
+
// an \`openGraph\` or \`twitter\` object in a page.
|
|
325
|
+
//
|
|
326
|
+
// WHY: Next.js merges metadata SHALLOWLY, per top-level key. A page that sets
|
|
327
|
+
// \`openGraph: { title, description }\` REPLACES the root layout's whole
|
|
328
|
+
// openGraph object — og:type and og:site_name silently disappear — and a
|
|
329
|
+
// matching \`twitter: { title, description }\` drops
|
|
330
|
+
// \`card: "summary_large_image"\`, so a 1200x630 image renders as a small
|
|
331
|
+
// square. \`next build\` reports nothing; the source reads as if it composes.
|
|
332
|
+
// The only way to see it is to diff the served HTML.
|
|
333
|
+
|
|
334
|
+
import type { Metadata } from "next";
|
|
335
|
+
|
|
336
|
+
/** Brand name, appended to page titles and emitted as og:site_name. */
|
|
337
|
+
export const SITE_NAME = "{{brand_name}}";
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* The site-wide OG image, served by app/opengraph-image.tsx.
|
|
341
|
+
*
|
|
342
|
+
* Set explicitly on every page because declaring \`openGraph\` at all SUPPRESSES
|
|
343
|
+
* the inherited opengraph-image file convention. Verified against served HTML:
|
|
344
|
+
* a child page that declares openGraph and omits \`images\` ships NO og:image —
|
|
345
|
+
* so "just leave images out" silently costs every child page its social card.
|
|
346
|
+
* (A colocated opengraph-image.tsx in the SAME segment does survive, which is
|
|
347
|
+
* why the home page looked fine and hid this.)
|
|
348
|
+
*/
|
|
349
|
+
export const DEFAULT_OG_IMAGE = "/opengraph-image";
|
|
350
|
+
|
|
351
|
+
export type PageMetadataInput = {
|
|
352
|
+
/**
|
|
353
|
+
* The page-specific part of the title, e.g. "About" or "Frog Species Guide".
|
|
354
|
+
* " | " + SITE_NAME is appended for you — do NOT include the brand here
|
|
355
|
+
* unless you also pass \`brandSuffix: false\`.
|
|
356
|
+
*/
|
|
357
|
+
title: string;
|
|
358
|
+
/** Set false when \`title\` already carries the brand (the home page does). */
|
|
359
|
+
brandSuffix?: boolean;
|
|
360
|
+
/** Unique, page-specific. Never reuse the site description. */
|
|
361
|
+
description: string;
|
|
362
|
+
/** Root-relative path, e.g. "/" or "/about". Becomes the canonical URL. */
|
|
363
|
+
path: string;
|
|
364
|
+
/** "article" for posts and news; "website" for everything else. */
|
|
365
|
+
ogType?: "website" | "article";
|
|
366
|
+
/**
|
|
367
|
+
* A page-specific OG/Twitter image. Defaults to the site-wide
|
|
368
|
+
* DEFAULT_OG_IMAGE — do NOT omit it expecting inheritance, there is none
|
|
369
|
+
* (see DEFAULT_OG_IMAGE above).
|
|
370
|
+
*
|
|
371
|
+
* Pass \`null\` in the one case where that is wrong: this segment has its OWN
|
|
372
|
+
* colocated opengraph-image.tsx. An explicit \`images\` value REPLACES the file
|
|
373
|
+
* convention rather than adding to it, so without \`null\` the page would ship
|
|
374
|
+
* the site-wide image and silently ignore the one sitting next to it. (Not a
|
|
375
|
+
* duplicate — a substitution, which is harder to notice.)
|
|
376
|
+
*/
|
|
377
|
+
images?: NonNullable<Metadata["openGraph"]>["images"] | null;
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
export function pageMetadata({
|
|
381
|
+
title,
|
|
382
|
+
brandSuffix = true,
|
|
383
|
+
description,
|
|
384
|
+
path,
|
|
385
|
+
ogType = "website",
|
|
386
|
+
images = [DEFAULT_OG_IMAGE],
|
|
387
|
+
}: PageMetadataInput): Metadata {
|
|
388
|
+
const fullTitle = brandSuffix ? \`\${title} | \${SITE_NAME}\` : title;
|
|
389
|
+
|
|
390
|
+
// Shared between openGraph and twitter so the two can never drift apart.
|
|
391
|
+
const shared = {
|
|
392
|
+
title: fullTitle,
|
|
393
|
+
description,
|
|
394
|
+
// \`null\` means "this segment has its own opengraph-image.tsx" — omit the
|
|
395
|
+
// key so the colocated file convention supplies the image instead.
|
|
396
|
+
...(images === null ? {} : { images }),
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
return {
|
|
400
|
+
// \`absolute\` opts out of the layout's title.template. The template applies
|
|
401
|
+
// to CHILD segments only and never to app/page.tsx, so composing here
|
|
402
|
+
// instead is what makes root and nested pages behave identically.
|
|
403
|
+
title: { absolute: fullTitle },
|
|
404
|
+
description,
|
|
405
|
+
alternates: { canonical: path },
|
|
406
|
+
// Complete object, every time — this is the whole point of the helper.
|
|
407
|
+
openGraph: {
|
|
408
|
+
...shared,
|
|
409
|
+
// Written as a branch rather than \`type: ogType\` because Next's
|
|
410
|
+
// OpenGraph type is a discriminated union; a widened string does not
|
|
411
|
+
// typecheck.
|
|
412
|
+
...(ogType === "article" ? { type: "article" as const } : { type: "website" as const }),
|
|
413
|
+
siteName: SITE_NAME,
|
|
414
|
+
// Relative — Next resolves it against metadataBase, so each page gets its
|
|
415
|
+
// OWN og:url rather than the site root.
|
|
416
|
+
url: path,
|
|
417
|
+
},
|
|
418
|
+
twitter: {
|
|
419
|
+
...shared,
|
|
420
|
+
// Dropping this is the silent half of the shallow-merge trap: the card
|
|
421
|
+
// degrades from a 1200x630 banner to a small square.
|
|
422
|
+
card: "summary_large_image",
|
|
423
|
+
},
|
|
424
|
+
};
|
|
425
|
+
}
|
|
426
|
+
`;
|
|
139
427
|
const TSCONFIG_TEMPLATE = `{
|
|
140
428
|
"compilerOptions": {
|
|
141
429
|
"target": "ES2022",
|
|
@@ -161,6 +449,11 @@ const TSCONFIG_TEMPLATE = `{
|
|
|
161
449
|
const APP_LAYOUT_TEMPLATE = `// Root layout — SEO baseline wiring per Z2W standing org requirement
|
|
162
450
|
// 2026-05-30. Every indexable page MUST export its own \`metadata\`; do not
|
|
163
451
|
// rely on these defaults to fill in per-page values.
|
|
452
|
+
//
|
|
453
|
+
// ⚠️ These \`openGraph\` / \`twitter\` objects are DEFAULTS, not a base to extend.
|
|
454
|
+
// Next.js merges metadata shallowly per top-level key, so any page declaring a
|
|
455
|
+
// partial \`openGraph\` REPLACES the whole object below. Build page metadata with
|
|
456
|
+
// pageMetadata() from lib/seo/page-metadata.ts and this never comes up.
|
|
164
457
|
|
|
165
458
|
import type { Metadata, Viewport } from "next";
|
|
166
459
|
import { Analytics } from "@/lib/analytics/Analytics";
|
|
@@ -182,6 +475,10 @@ export const metadata: Metadata = {
|
|
|
182
475
|
title: "{{brand_name}} — {{slug}}",
|
|
183
476
|
description: "{{description}}",
|
|
184
477
|
type: "website",
|
|
478
|
+
// Present here as well as in pageMetadata(), so a hand-written page that
|
|
479
|
+
// sets no openGraph at all still inherits og:site_name. Verified missing
|
|
480
|
+
// from the served HTML of such a page before this line existed.
|
|
481
|
+
siteName: "{{brand_name}}",
|
|
185
482
|
url: siteUrl,
|
|
186
483
|
},
|
|
187
484
|
twitter: {
|
|
@@ -378,23 +675,28 @@ const APP_PAGE_TEMPLATE = `// Home page — per-page \`metadata\` is mandatory p
|
|
|
378
675
|
// the title + description with intentional, page-specific copy (do NOT
|
|
379
676
|
// inherit the root defaults).
|
|
380
677
|
//
|
|
381
|
-
// ⚠️
|
|
382
|
-
//
|
|
383
|
-
//
|
|
384
|
-
//
|
|
385
|
-
//
|
|
386
|
-
//
|
|
387
|
-
//
|
|
388
|
-
// the
|
|
389
|
-
//
|
|
678
|
+
// ⚠️ Build metadata with pageMetadata(). Do NOT hand-write an \`openGraph\` or
|
|
679
|
+
// \`twitter\` object here: Next.js merges metadata SHALLOWLY per top-level key,
|
|
680
|
+
// so a partial \`openGraph\` REPLACES the layout's whole object and silently
|
|
681
|
+
// deletes og:type / og:site_name, while a partial \`twitter\` drops
|
|
682
|
+
// \`card: "summary_large_image"\`. See lib/seo/page-metadata.ts.
|
|
683
|
+
//
|
|
684
|
+
// ⚠️ \`brandSuffix: false\` because this title already carries the brand. It has
|
|
685
|
+
// to: the root layout's \`title.template\` applies to CHILD segments ONLY, and
|
|
686
|
+
// app/page.tsx shares the ROOT segment with app/layout.tsx, so a bare fragment
|
|
687
|
+
// here (the old \`title: "Home"\`) rendered literally as \`<title>Home</title>\` on
|
|
688
|
+
// the most-linked page on the site — silently, with \`next build\` happy. Pages
|
|
689
|
+
// in CHILD segments pass a fragment and let pageMetadata() append the brand.
|
|
690
|
+
// (Both traps found by \`site-control\` dogfooding this scaffold, 2026-07-28/29.)
|
|
390
691
|
|
|
391
|
-
import
|
|
692
|
+
import { pageMetadata } from "@/lib/seo/page-metadata";
|
|
392
693
|
|
|
393
|
-
export const metadata
|
|
694
|
+
export const metadata = pageMetadata({
|
|
394
695
|
title: "{{brand_name}} — {{slug}}",
|
|
696
|
+
brandSuffix: false,
|
|
395
697
|
description: "{{description}}",
|
|
396
|
-
|
|
397
|
-
};
|
|
698
|
+
path: "/",
|
|
699
|
+
});
|
|
398
700
|
|
|
399
701
|
export default function HomePage() {
|
|
400
702
|
return (
|
|
@@ -440,25 +742,45 @@ export default function sitemap(): MetadataRoute.Sitemap {
|
|
|
440
742
|
return [
|
|
441
743
|
{
|
|
442
744
|
url: siteUrl,
|
|
443
|
-
lastModified
|
|
745
|
+
// \`lastModified\` is deliberately OMITTED rather than set to \`new Date()\`.
|
|
746
|
+
// An always-now value claims the page changed on every fetch of the
|
|
747
|
+
// sitemap; Google documents ignoring \`lastmod\` once it proves unreliable,
|
|
748
|
+
// so a value that is always wrong spends the signal to say nothing — worse
|
|
749
|
+
// than not sending it. Add it back when you have a REAL content timestamp
|
|
750
|
+
// (a CMS \`updated_at\`, a file mtime, a build-pinned constant).
|
|
444
751
|
changeFrequency: "weekly",
|
|
445
752
|
priority: 1,
|
|
446
753
|
},
|
|
447
754
|
];
|
|
448
755
|
}
|
|
449
756
|
`;
|
|
450
|
-
const APP_ROBOTS_TEMPLATE = `// Robots generator — production
|
|
451
|
-
//
|
|
452
|
-
//
|
|
757
|
+
const APP_ROBOTS_TEMPLATE = `// Robots generator — indexable ONLY on a production deployment that also has a
|
|
758
|
+
// real canonical domain. Everything else (preview, staging, and a production
|
|
759
|
+
// deploy still on the placeholder domain) emits \`Disallow: /\`.
|
|
760
|
+
//
|
|
761
|
+
// Two conditions, not one. Gating on \`VERCEL_ENV\` ALONE means the very first
|
|
762
|
+
// \`vercel --prod\` — or the first push after connecting the repo, since
|
|
763
|
+
// auto-deploy is on by default — publishes \`Allow: /\` advertising a sitemap of
|
|
764
|
+
// \`{{slug}}.example.com\` URLs, a domain this project does not own.
|
|
765
|
+
// \`NEXT_PUBLIC_SITE_URL\` is unset on day one by definition, so the placeholder is
|
|
766
|
+
// what ships. (Reported by \`site-control\` 2026-07-29 after it cost two deferred
|
|
767
|
+
// deploys: the deploy was never the hazard, the gate was.)
|
|
768
|
+
//
|
|
769
|
+
// ⚠️ robots.txt and sitemap.xml are PRERENDERED at build time (\`○ (Static)\`), so
|
|
770
|
+
// setting NEXT_PUBLIC_SITE_URL later requires a REDEPLOY — editing the env var
|
|
771
|
+
// alone changes nothing.
|
|
772
|
+
//
|
|
773
|
+
// For non-Vercel hosts, swap the VERCEL_ENV check inside
|
|
774
|
+
// lib/seo/canonical-host.mjs for the equivalent (e.g. \`CF_PAGES_BRANCH === 'main'\`).
|
|
453
775
|
|
|
454
776
|
import type { MetadataRoute } from "next";
|
|
777
|
+
import { isIndexableDeployment } from "@/lib/seo/canonical-host.mjs";
|
|
455
778
|
|
|
456
779
|
// \`||\` not \`??\` — a blank NEXT_PUBLIC_SITE_URL must fall back (see app/layout.tsx).
|
|
457
780
|
const siteUrl = process.env.NEXT_PUBLIC_SITE_URL || "https://{{slug}}.example.com";
|
|
458
|
-
const isProduction = process.env.VERCEL_ENV === "production";
|
|
459
781
|
|
|
460
782
|
export default function robots(): MetadataRoute.Robots {
|
|
461
|
-
if (!
|
|
783
|
+
if (!isIndexableDeployment()) {
|
|
462
784
|
return {
|
|
463
785
|
rules: { userAgent: "*", disallow: "/" },
|
|
464
786
|
};
|
|
@@ -509,7 +831,9 @@ Per Z2W standing org requirement 2026-05-30. Run before adding a new page AND be
|
|
|
509
831
|
## Per-page checklist (every new page)
|
|
510
832
|
|
|
511
833
|
- [ ] Page exports its own \`metadata\` — unique title, unique description, canonical URL
|
|
512
|
-
- [ ]
|
|
834
|
+
- [ ] Metadata built with \`pageMetadata()\` from \`lib/seo/page-metadata.ts\` — **never hand-write \`openGraph\` or \`twitter\` in a page.** Next.js merges metadata SHALLOWLY per top-level key: a partial \`openGraph: { title, description }\` REPLACES the layout's whole object (deleting \`og:type\` and \`og:site_name\`) and a partial \`twitter\` drops \`card: "summary_large_image"\`, so a 1200×630 image renders as a small square. Nothing warns — \`next build\` passes and the source reads as if it composes. Verify by diffing the served HTML, not the source.
|
|
835
|
+
- [ ] Title composition correct: a page in a CHILD segment passes a fragment (\`title: "About"\`) and lets \`pageMetadata()\` append the brand; \`app/page.tsx\` passes \`brandSuffix: false\` because the root layout's \`title.template\` cannot reach it
|
|
836
|
+
- [ ] OG image reaches the page. \`pageMetadata()\` sets it for you; the trap it closes is that declaring \`openGraph\` at all SUPPRESSES the inherited \`app/opengraph-image.tsx\`, so a child page that declares openGraph without \`images\` ships **no** \`og:image\`. If the segment has its own colocated \`opengraph-image.tsx\`, pass \`images: null\` — an explicit value replaces the file convention rather than adding to it, so the page would otherwise use the site-wide image and silently ignore the one next to it
|
|
513
837
|
- [ ] Page-specific OG image set if branding differs from default
|
|
514
838
|
- [ ] Exactly one \`<h1>\` stating the page's primary topic
|
|
515
839
|
- [ ] Heading hierarchy logical (H1 → H2 → H3, no skipped levels)
|
|
@@ -536,9 +860,11 @@ Per Z2W standing org requirement 2026-05-30. Run before adding a new page AND be
|
|
|
536
860
|
## Wired at instantiation by \`@zero2webmaster/starter-kit\`
|
|
537
861
|
|
|
538
862
|
- ✅ \`app/layout.tsx\` — root metadata + JSON-LD Organization
|
|
539
|
-
- ✅ \`app/page.tsx\` — per-page metadata template
|
|
863
|
+
- ✅ \`app/page.tsx\` — per-page metadata template, built with \`pageMetadata()\`
|
|
864
|
+
- ✅ \`lib/seo/page-metadata.ts\` — the one metadata builder; closes the shallow-merge trap by emitting a COMPLETE \`openGraph\` + \`twitter\` object on every page
|
|
540
865
|
- ✅ \`app/sitemap.ts\`
|
|
541
|
-
- ✅ \`app/robots.ts\` (
|
|
866
|
+
- ✅ \`app/robots.ts\` (indexable requires production **and** a real canonical domain — see \`lib/seo/canonical-host.mjs\`)
|
|
867
|
+
- ⚠️ \`robots.txt\` + \`sitemap.xml\` are PRERENDERED at build time. Until \`NEXT_PUBLIC_SITE_URL\` is your real domain this site is \`Disallow: /\` **by design**; setting the env var requires a **redeploy** to take effect. Verify with \`curl https://your-domain/robots.txt\`.
|
|
542
868
|
- ✅ \`app/opengraph-image.tsx\` (placeholder — replace before launch)
|
|
543
869
|
- ✅ Fathom three-file pattern (\`lib/analytics/\`) mounted as \`<Analytics />\`; RouteTracker fires \`trackPageview()\` on route change (gated on \`NEXT_PUBLIC_FATHOM_SITE_ID\`)
|
|
544
870
|
- ✅ \`NEXT_PUBLIC_SITE_URL\` env var stub for \`metadataBase\`
|
|
@@ -562,6 +888,41 @@ NEXT_PUBLIC_SITE_URL=https://{{slug}}.example.com
|
|
|
562
888
|
# One Fathom site = one deployment.
|
|
563
889
|
NEXT_PUBLIC_FATHOM_SITE_ID=
|
|
564
890
|
`;
|
|
891
|
+
/**
|
|
892
|
+
* The `CANONICAL_HOSTS` allowlist seam.
|
|
893
|
+
*
|
|
894
|
+
* Appended when the project sends auth email (`sendsEmail`) or routes by Host
|
|
895
|
+
* (`hostRoutedTenancy`) — the two shapes that have somewhere to enforce it.
|
|
896
|
+
*
|
|
897
|
+
* Why the scaffolder plants the env var and the pointer rather than the code:
|
|
898
|
+
* this CLI does not emit `auth.ts` (it emits no auth code at all), so there is no
|
|
899
|
+
* emitted host check to patch. The gap `audit-engine` measured on 2026-07-29 —
|
|
900
|
+
* 10 repos with `trustHost: true`, no `AUTH_URL`, and only 2 validating the host
|
|
901
|
+
* — propagated through the *guidance*, not through this scaffold. So the
|
|
902
|
+
* scaffolder's honest half is the seam: an env var that exists on day one, and a
|
|
903
|
+
* pointer at the recipe, in the file the next agent actually opens.
|
|
904
|
+
*/
|
|
905
|
+
const CANONICAL_HOSTS_ENV_BLOCK = `
|
|
906
|
+
# ── Canonical host allowlist ────────────────────────────────────────────────
|
|
907
|
+
# Comma-separated list of the hostnames this deployment legitimately answers on.
|
|
908
|
+
# Normalize to lowercase when you parse it.
|
|
909
|
+
#
|
|
910
|
+
# UNSET MUST MEAN NOBODY, NOT EVERYBODY. An env-var typo has to lock the door,
|
|
911
|
+
# not remove it — the same fail-closed-on-empty rule as ALLOWED_EMAILS.
|
|
912
|
+
#
|
|
913
|
+
# Magic-link auth needs this and it is not optional: \`trustHost: true\` with no
|
|
914
|
+
# AUTH_URL (the correct Z2W setting — a fixed AUTH_URL breaks tenant vanity
|
|
915
|
+
# domains) means Auth.js derives every magic-link URL from the incoming Host
|
|
916
|
+
# header with NOTHING validating it. An attacker can request a link for someone
|
|
917
|
+
# else's address on a forged Host; the victim gets a genuine, correctly-signed
|
|
918
|
+
# email pointing at the attacker's server. Validate inside
|
|
919
|
+
# sendVerificationRequest and fail CLOSED — send nothing, do not fall back to a
|
|
920
|
+
# canonical host (that is an enumeration oracle). Allow anything when
|
|
921
|
+
# NODE_ENV !== "production" so preview deployments and localhost keep working.
|
|
922
|
+
#
|
|
923
|
+
# Copy-paste recipe + the isKnownHost() helper: [[z2w-magic-link-auth]] §0 rule 2b.
|
|
924
|
+
CANONICAL_HOSTS=
|
|
925
|
+
`;
|
|
565
926
|
/**
|
|
566
927
|
* Merge the email SDK deps into an already-substituted package.json string.
|
|
567
928
|
* Only called on the email path, so the no-email package.json stays the exact
|
|
@@ -576,15 +937,31 @@ export function scaffoldNextjs(inputs, opts) {
|
|
|
576
937
|
const spec = resolveBrandSpec(inputs);
|
|
577
938
|
const base = commonBaseFiles(inputs, opts, NARRATIVE);
|
|
578
939
|
const sendsEmail = inputs.sendsEmail === true;
|
|
940
|
+
const hostRouted = inputs.hostRoutedTenancy === true;
|
|
579
941
|
let packageJson = sub(PACKAGE_JSON_TEMPLATE, inputs, opts, spec);
|
|
580
942
|
if (sendsEmail)
|
|
581
943
|
packageJson = withEmailDeps(packageJson);
|
|
582
944
|
let envExample = sub(ENV_EXAMPLE_TEMPLATE, inputs, opts, spec);
|
|
583
945
|
if (sendsEmail)
|
|
584
946
|
envExample += EMAIL_ENV_BLOCK;
|
|
947
|
+
// The host allowlist serves auth email (magic links derive URLs from the Host)
|
|
948
|
+
// and Host-routed tenancy (the Host selects the tenant). Emitted once for both.
|
|
949
|
+
if (sendsEmail || hostRouted)
|
|
950
|
+
envExample += CANONICAL_HOSTS_ENV_BLOCK;
|
|
585
951
|
const typeSpecific = [
|
|
586
952
|
{ path: "package.json", content: packageJson },
|
|
587
|
-
{
|
|
953
|
+
{
|
|
954
|
+
path: "next.config.mjs",
|
|
955
|
+
content: sub(hostRouted ? NEXT_CONFIG_HOST_ROUTED_TEMPLATE : NEXT_CONFIG_TEMPLATE, inputs, opts, spec),
|
|
956
|
+
},
|
|
957
|
+
{
|
|
958
|
+
path: "lib/seo/canonical-host.mjs",
|
|
959
|
+
content: sub(CANONICAL_HOST_MODULE_TEMPLATE, inputs, opts, spec),
|
|
960
|
+
},
|
|
961
|
+
{
|
|
962
|
+
path: "lib/seo/page-metadata.ts",
|
|
963
|
+
content: sub(PAGE_METADATA_MODULE_TEMPLATE, inputs, opts, spec),
|
|
964
|
+
},
|
|
588
965
|
{ path: "tsconfig.json", content: sub(TSCONFIG_TEMPLATE, inputs, opts, spec) },
|
|
589
966
|
{ path: "app/layout.tsx", content: sub(APP_LAYOUT_TEMPLATE, inputs, opts, spec) },
|
|
590
967
|
{ path: "app/page.tsx", content: sub(APP_PAGE_TEMPLATE, inputs, opts, spec) },
|
|
@@ -617,6 +994,12 @@ export function scaffoldNextjs(inputs, opts) {
|
|
|
617
994
|
path: ".env.local",
|
|
618
995
|
content: localEnvFrom(envExample, ".env.local", inputs.slug),
|
|
619
996
|
});
|
|
997
|
+
if (hostRouted) {
|
|
998
|
+
typeSpecific.push({
|
|
999
|
+
path: "middleware.ts",
|
|
1000
|
+
content: sub(MIDDLEWARE_HOST_GUARD_TEMPLATE, inputs, opts, spec),
|
|
1001
|
+
});
|
|
1002
|
+
}
|
|
620
1003
|
if (sendsEmail) {
|
|
621
1004
|
typeSpecific.push(...emailFiles(inputs, opts, spec, "nextjs"));
|
|
622
1005
|
}
|
|
@@ -632,6 +1015,15 @@ export const NEXTJS_SEO_BASELINE_PATHS = [
|
|
|
632
1015
|
"app/page.tsx",
|
|
633
1016
|
"app/sitemap.ts",
|
|
634
1017
|
"app/robots.ts",
|
|
1018
|
+
// The shared canonical-host predicate. Part of the baseline because the
|
|
1019
|
+
// indexability gate in app/robots.ts and the alias redirect in next.config.mjs
|
|
1020
|
+
// both read it — a scaffold missing it has no indexability gate at all.
|
|
1021
|
+
"lib/seo/canonical-host.mjs",
|
|
1022
|
+
// The one metadata builder. Part of the baseline because a scaffold without
|
|
1023
|
+
// it has no defence against Next's shallow per-top-level-key metadata merge —
|
|
1024
|
+
// the second page added to the project silently strips og:type / og:site_name
|
|
1025
|
+
// and downgrades the Twitter card.
|
|
1026
|
+
"lib/seo/page-metadata.ts",
|
|
635
1027
|
"app/opengraph-image.tsx",
|
|
636
1028
|
// Fathom (SEO baseline item 7) — the three-file pattern; the loader alone
|
|
637
1029
|
// (data-auto="false" with no RouteTracker) records zero pageviews.
|
package/dist/standards.d.ts
CHANGED
|
@@ -51,7 +51,7 @@ export interface StandardsResolution {
|
|
|
51
51
|
* family — the safe default for anything else with `has_web_ui=true`.
|
|
52
52
|
*/
|
|
53
53
|
export declare function fathomEnvVarFor(projectType: ProjectType): string;
|
|
54
|
-
export declare const CANONICAL_COORDINATION_BLOCK_VERSION = "v0.1.
|
|
54
|
+
export declare const CANONICAL_COORDINATION_BLOCK_VERSION = "v0.1.16";
|
|
55
55
|
/**
|
|
56
56
|
* Resolve which standards apply to `inputs` and render the standards markdown
|
|
57
57
|
* body suitable for `.replace()`-ing into the `<!-- STANDARDS_BLOCK -->`
|
package/dist/standards.js
CHANGED
|
@@ -309,7 +309,8 @@ const SENTRY_BODY = `### Sentry runtime-error tracking (customer-facing web app)
|
|
|
309
309
|
> 2. **DSN lives in config, NOT an env var.** The DSN is a publishable identifier (not a secret) — hard-code it in the Sentry config files the wizard generates; do NOT introduce a \`NEXT_PUBLIC_SENTRY_DSN\`. The one real secret is \`SENTRY_AUTH_TOKEN\` (build-time source-map upload) — scope it **Production-only** in Vercel and keep it out of the client bundle.
|
|
310
310
|
> 3. **Feature-flag defaults:** Tracing sample rate 1.0 (100%) at Z2W volume; Session Replay 10% of sessions / 100% of sessions-with-errors; Logs on; \`sendDefaultPii: true\` — with the caveat that a Sentry payload then carries user IP + request headers, so never forward it verbatim into a shared surface (e.g. the bulletin \`## Incidents\` pipe strips to summary + link + timestamp).
|
|
311
311
|
> 4. **Smoke it, then delete the smoke.** Add a throwaway auth-gated server-throw route (\`/api/boom\` style), confirm the error + replay land in Sentry and the alert email fires, then DELETE the route and the wizard's noisy example page (it's a honeypot that inflates your error count). Ship this cleanup as its own small commit.
|
|
312
|
-
> 5. **
|
|
312
|
+
> 5. **The wizard writes \`silent: !process.env.CI\`, so a missing \`SENTRY_AUTH_TOKEN\` is SILENT LOCALLY and LOUD ON CI.** Quiet on your machine is by configuration, not by design — \`CI\` is unset locally and Vercel sets \`CI=1\`, where the plugin warns **three times, once per runtime**. So do NOT conclude from a clean local build that source-map upload emits nothing: **grep the deployed build log for \`No auth token provided\`** — a free check that beats a manual dashboard visit. (Reported by \`site-control\` 2026-07-30 after documenting the opposite in five places from a local measurement. The general shape, which is worth more than the Sentry detail: **a fact established under one configuration silently changes meaning under another** — so print or fetch what actually resolved, in the environment that will run it.)
|
|
313
|
+
> 6. **2025 Sentry-UI quirks that waste time:** issue **alert rules** live at \`/alerts/rules/\` (NOT \`/monitors/alerts/\`); the "Test Notification" button does NOT auto-save the rule (save explicitly or it evaporates); the wizard's example page throws on every load until you remove it.
|
|
313
314
|
>
|
|
314
315
|
> **When to SKIP (do not wire Sentry):** WordPress sites (error tracking via Z2W Admin Suite Diagnostics + FluentSMTP logs); CLI libraries and protocol repos (no request surface); Cloudflare Workers / node-service / python-service that are API-only (the \`-i nextjs\` wizard doesn't fit — revisit per-runtime later); internal-only admin tools with a single operator who sees errors directly. The rule of thumb: wire it for any public-or-customer-facing Next.js / CF-Pages app that will have real users.
|
|
315
316
|
>
|
|
@@ -325,7 +326,7 @@ const NEON_CAREFUL_BODY = `### Neon-careful (Neon Postgres)
|
|
|
325
326
|
// `zero2webmaster/z2w-agent-coordination`'s AGENT_PROTOCOL.md when the embedded
|
|
326
327
|
// block's mechanics change (drift-detection Signal A greps for this exact token).
|
|
327
328
|
// When you sync a newer canonical block below, bump this to match its comment.
|
|
328
|
-
export const CANONICAL_COORDINATION_BLOCK_VERSION = "v0.1.
|
|
329
|
+
export const CANONICAL_COORDINATION_BLOCK_VERSION = "v0.1.16";
|
|
329
330
|
/**
|
|
330
331
|
* The Agent Coordination section, emitted as its own TOP-LEVEL `## Agent
|
|
331
332
|
* Coordination` section (NOT a `###` standards subsection). The bulk is the
|
|
@@ -371,7 +372,7 @@ This project participates in the Z2W cross-project coordination bulletin.
|
|
|
371
372
|
\`\`\`
|
|
372
373
|
- 2026-07-25 · z2w-starter-kit · ACTION · Trim your bulletin file — it's over the 256 KB read-cap · §Open questions
|
|
373
374
|
\`\`\`
|
|
374
|
-
Applies to every inbound form: a \`[→ {them}]\` question, a heads-up you filed in their file, or a maintainer directive. **The recipient deletes the line when they handle it**, so leaving it un-deleted is the signal that the item is still live. *(Adopted 2026-07-25 from \`z2w-starter-kit\`'s 2026-07-15 proposal on Kerry's observation that finding messages addressed to a project was too hard — one session had to grep a 705 KB file across three sections to find a directive aimed at it — and \`z2w-agent-command-center\`'s independent endorsement after the same failure bit it. The Command Center renders this block as the phone-first "addressed to you" queue.)*
|
|
375
|
+
Applies to every inbound form: a \`[→ {them}]\` question, a heads-up you filed in their file, or a maintainer directive. **The recipient deletes the line when they handle it**, so leaving it un-deleted is the signal that the item is still live. **Two send-side rules (v0.1.22, both detailed in §8.11):** (1) **grep their file for an existing thread on your topic before you file** — you already have the file open to append, so the check is free; if a thread exists, \`↳\` co-sign it (saying what's *different* about your instance) rather than opening a second one; (2) **if you later WITHDRAW an item, delete your own triage line yourself** — post the \`↳ retracted\` reply first, then remove the line. Retraction is the only case where a sender deletes; \`ACTION\` outranks everything in the recipient's queue, so a withdrawn ACTION is not clutter, it is real work being pushed down the list. *(Adopted 2026-07-25 from \`z2w-starter-kit\`'s 2026-07-15 proposal on Kerry's observation that finding messages addressed to a project was too hard — one session had to grep a 705 KB file across three sections to find a directive aimed at it — and \`z2w-agent-command-center\`'s independent endorsement after the same failure bit it. The Command Center renders this block as the phone-first "addressed to you" queue.)*
|
|
375
376
|
- **ANSWERING a \`[→ you]\` question counts as "writing something addressed to another project" — so the reply ALSO needs a \`## 📥 Needs attention\` line, in the ASKER's file (v0.1.21).** This is the case the rule above always covered in principle and that everyone (including the maintainer) reads past in practice, because replying *feels* like closing an item rather than sending one. It isn't. Per §8.2 the thread lives in **your** file, which means **the asker has nothing in their own file to tell them an answer arrived** — they filed into your file and then never look at it again. Posting the \`↳\` is not delivering it.
|
|
376
377
|
\`\`\`
|
|
377
378
|
- 2026-07-27 · z2w-agent-coordination · FYI · RULING on your \`## Integrations\` question — answered in full on the thread in my file · projects/z2w-agent-coordination.md §Open questions
|
|
@@ -409,6 +410,11 @@ This project participates in the Z2W cross-project coordination bulletin.
|
|
|
409
410
|
**The trigger is "carries cross-project signal," NOT "committed code" (v0.1.15).** A decision, a heads-up, a capability→home mapping, a naming or scope change, a new build-target, an answered question, a discovered gotcha — all qualify, and **synthesis, audit, and planning sessions routinely commit zero code yet carry the highest cross-project value.** An agent that gates Tier 2 on \`git log\` says nothing exactly when it has the most to say. Skip Tier 2 only when the session genuinely produced nothing anyone else would act on (pure local exploration with no outcome) — and Tier 1 still runs even then. *(Adopted 2026-07-25 from \`z2w-starter-kit\`'s 2026-07-11 ask on Kerry's instruction, after a zero-commit \`z2w-forms\` extraction audit generated a new build-target, a Kerry decision, a delivery model, a naming fix, and heads-ups landing on three other projects — none of which a code-gated wrap-up would have published.)*
|
|
410
411
|
- **Keep \`## Integrations\` + your Live status current — a never-ask standing step, exactly like \`## Current focus\` (v0.1.14).** If this session changed how this project relates to another Z2W app — it started consuming an engine/service, stopped using one, or became a provider another app now depends on — update your file's \`## Integrations\` edges. If the project's lifecycle changed — scaffolded → live in prod, went dormant, retired — update the **Live status** line and its date. This is the capture mechanism behind the ecosystem dependency map + live-status badges on \`agents.z2w.us\`; a stale edge or status silently misleads every other agent (real 2026-07-20 miss: an audit called a LIVE engine "unbuilt" because no single place recorded its status). Decide and do it — do not ask. Absent section = nothing to report yet; create it lazily the first time you have an edge or a status to record. Schema + conventions in §8.10.
|
|
411
412
|
- **Size discipline (v0.1.11):** before appending, if \`projects/{this-project}.md\` is approaching ~200 KB (the point where agents can no longer \`Read\` it in one call), trim FIRST — archive old \`## Active sessions\` and \`## Recent commits\` entries and resolved \`## Open questions\` threads into \`projects/{this-project}-archive.md\` (a separate, commit-flagged operation). Keep your live file readable whole. \`## Current focus\` is rewritten in place (never appended), which is the main thing that keeps a project file from growing without bound — never let a single field accumulate a multi-session history.
|
|
413
|
+
- **Your project file is a COORDINATION SURFACE, not a log (v0.1.22).** The test, and it is a good one: **"would another agent load this file to answer a question?"** Session recaps, npm publish state, test counts, defect post-mortems and build narrative all fail it — that is \`STATUS.md\` / \`CHANGELOG.md\` content in your own repo, and duplicating it here makes ~40 other agents pay for it on every read while approximately none of them need it. Two bright lines:
|
|
414
|
+
1. **\`## Current focus\` and \`## Active sessions\` answer "what is this project doing, and is it alive" — nothing more.** Current focus ≲1.5 KB (it renders on Kerry's phone); each Active-sessions entry ≲400 bytes — one line: what shipped, the test count, a commit SHA. The narrative goes in your own repo, where you are already writing it.
|
|
415
|
+
2. **Archive a thread in the same commit that resolves it.** Not in a later sweep. If you post a closing \`↳\`, you move the thread. This is the only self-enforcing rule of the set, because the agent that knows a thread is done is the agent closing it. *(Do NOT auto-archive on "reply older than N days" — a reply is not a resolution, and several of the longest-running live threads in this bulletin have replies. Resolution is a judgment, so the action belongs at the moment of judgment.)* **"Resolved" means BOTH parties are done — never archive a thread you are the ASKER on until the answer lands.** The live-ness signal for a thread you are waiting on is a \`## 📥 Needs attention\` line in *someone else's* file, which you cannot see from your own, so "no live line in my queue" is not evidence the thread is closed. *(Found the hard way 2026-07-29: \`z2w-starter-kit\`'s own careful trim — which explicitly spared every thread with a live queue line — archived the very thread carrying its unanswered proposal, because the waiting line was in the maintainer's queue.)*
|
|
416
|
+
|
|
417
|
+
**Enforced at push, not by good intentions:** \`.github/workflows/file-size-check.yml\` runs \`scripts/check-file-sizes.sh\` on every push touching \`projects/**.md\` or \`global.md\` — hard-fail over 256 KB, warning over 200 KB, \`*-archive.md\` exempt by design. *(Adopted 2026-07-29 from \`z2w-starter-kit\`'s 2026-07-27 proposal, made after it trimmed its own file three times in one month and re-grew it ~70 KB in a single session. Its rule 3 — a per-session soft byte budget — is deliberately NOT adopted: it fails for exactly the reason the v0.1.11 rule above fails, namely that it asks an agent to measure mid-task, and agents do not measure mid-task. Push is the one moment measurement is automatic and free. The check belongs to the repo it guards, so the maintainer wrote it rather than handing the offer back.)*
|
|
412
418
|
- \`git commit -m "{this-project}: {summary}"\` (see §8.2 for agent-identifier format in commit messages and session entries) and \`git push\`.
|
|
413
419
|
- If push fails due to concurrent write from another session: \`git pull --rebase\`, resolve any conflicts (they should be rare — append-only within sections), retry push.
|
|
414
420
|
- **Local auto-push hooks:** if your project has a post-commit hook that auto-pushes, expect it to race your explicit \`git push\` and grab the ref lock first. The commit still lands — verify with \`git log origin/main\` rather than re-pushing.
|
|
@@ -466,7 +472,11 @@ const SEO_BASELINE_BODY = `### SEO baseline (non-WP web UI)
|
|
|
466
472
|
> **Scope:** applies to every Z2W non-WP web app with a public indexable surface. Does NOT apply to: WordPress sites (RankMath), API-only services with no HTML surface, CLI libraries, protocol repos, Cloudflare Workers without a public HTML response.`;
|
|
467
473
|
const EMAIL_SERVICE_BODY = `### Email service selection (any project that will send mail)
|
|
468
474
|
|
|
469
|
-
> **Email service:** Kerry's portfolio has FOUR sanctioned email services covering distinct sweet spots — FluentCRM (WP marketing/CRM), Amazon SES (cheap high-volume transactional), Resend (developer-friendly transactional + NextAuth magic links + React Email), Cloudflare Email Service (Workers-native send/receive). Before wiring any email feature in this project — magic-link auth, transactional notification, marketing broadcast, anything — load [[email-service-router]] and walk the decision matrix. Do NOT introduce a fifth service (SendGrid, Mailgun, Postmark, Mailchimp, MailerSend, Brevo/Sendinblue, etc.) — the router skill explains why and routes to the right one of the four
|
|
475
|
+
> **Email service:** Kerry's portfolio has FOUR sanctioned email services covering distinct sweet spots — FluentCRM (WP marketing/CRM), Amazon SES (cheap high-volume transactional), Resend (developer-friendly transactional + NextAuth magic links + React Email), Cloudflare Email Service (Workers-native send/receive). Before wiring any email feature in this project — magic-link auth, transactional notification, marketing broadcast, anything — load [[email-service-router]] and walk the decision matrix. Do NOT introduce a fifth service (SendGrid, Mailgun, Postmark, Mailchimp, MailerSend, Brevo/Sendinblue, etc.) — the router skill explains why and routes to the right one of the four.
|
|
476
|
+
>
|
|
477
|
+
> **🔐 If this project uses magic-link auth, the Host allowlist is NOT optional — and the rule you already know is only half of it.** The Z2W rule is \`trustHost: true\` with **no** \`AUTH_URL\` (a fixed \`AUTH_URL\` breaks tenant vanity domains — that stands, do not reverse it). But "no \`AUTH_URL\`" also means **"accept ANY Host"** until you add an allowlist: Auth.js derives every magic-link URL from the incoming \`Host\` header with nothing validating it, so an attacker who requests a link for **someone else's** address on a forged Host causes that person to receive a genuine, correctly-signed email pointing at the attacker's server. **So: keep \`trustHost: true\`, keep \`AUTH_URL\` unset, AND validate the host** inside \`sendVerificationRequest\` against a \`CANONICAL_HOSTS\` env allowlist plus your DB's tenant domains. **Fail CLOSED — send nothing;** falling back to the canonical host is an enumeration oracle. **Unset \`CANONICAL_HOSTS\` must mean nobody, not everybody.** Allow anything when \`NODE_ENV !== "production"\` so preview deployments and localhost keep working. Copy-paste recipe: **[[z2w-magic-link-auth]] §0 rule 2b**.
|
|
478
|
+
>
|
|
479
|
+
> *Why this is spelled out here rather than left to the skill: \`audit-engine\` measured 10 Z2W repos on 2026-07-29 running \`trustHost: true\` with no \`AUTH_URL\` and only 2 validating the host. Several cite the rule by section number in a code comment — they followed the guidance exactly, and the guidance was missing its companion clause. **Honest scope: a guidance gap with one confirmed HIGH precedent (\`event-engine\` H-1, remediated with exactly this allowlist), not 10 confirmed vulnerabilities** — exploitability was not tested per repo.*`;
|
|
470
480
|
const MODERATION_BODY = `### Moderation baseline (user-generated content)
|
|
471
481
|
|
|
472
482
|
> **This project accepts user-generated content, so trust & safety is an at-instantiation decision — not a Phase-8 afterthought.** Before building the first surface where one user's input is shown to others (posts, comments, profiles, listings, direct messages), load [[moderation-system]] and follow its shape. It is battle-tested across two live Z2W apps (z2w-social shipped it Step 8; event-engine built the second reference implementation) — do NOT hand-roll a per-content-type moderation system.
|
package/dist/writer.js
CHANGED
|
@@ -405,6 +405,18 @@ export function parseScaffoldInputs(json) {
|
|
|
405
405
|
}
|
|
406
406
|
inputs.hasObservability = obj["hasObservability"];
|
|
407
407
|
}
|
|
408
|
+
// Optional: whether the incoming Host selects the tenant (a HOST-ROUTED
|
|
409
|
+
// multi-tenant app). Defaults to false (single-tenant). When true, the nextjs
|
|
410
|
+
// scaffolder omits the single-destination *.vercel.app alias redirect — wrong
|
|
411
|
+
// shape, there is no one canonical domain — and emits a `middleware.ts` host
|
|
412
|
+
// guard that 404s a known-non-canonical production host instead. Ruling
|
|
413
|
+
// 2026-07-30 across org-hq / site-control / z2w-member-match.
|
|
414
|
+
if (obj["hostRoutedTenancy"] !== undefined) {
|
|
415
|
+
if (typeof obj["hostRoutedTenancy"] !== "boolean") {
|
|
416
|
+
throw new WriterError(`--input field "hostRoutedTenancy" must be a boolean, got ${typeof obj["hostRoutedTenancy"]}.`);
|
|
417
|
+
}
|
|
418
|
+
inputs.hostRoutedTenancy = obj["hostRoutedTenancy"];
|
|
419
|
+
}
|
|
408
420
|
// Optional: the verbatim instantiation prompt, recorded on the Airtable row.
|
|
409
421
|
// The --input path has no brief to capture, so callers may supply it here;
|
|
410
422
|
// when omitted, the Airtable write reminds the agent to add it by hand.
|