承接 ADR-0014 §4「第二等产品镜像起必须子目录化 + rewrites 前缀映射并回溯睿视」。
上一轮(2026-12-02)只搬了字节,源码落在 public/ 根命名空间;本轮把源码、门禁、
发布职责一并收进本仓,authority 侧退役对应产物。
源码与 URL 契约:
- public/novavis/{index.html,css,js,assets,images/logos} 一棵树自成一体
- index.html 引用保持站点级绝对路径(/css /js /assets /images/logos)不变。
因为同一份字节要服务两个落点:官网镜像 novalon.cn/novavis/,以及独立子域
novavis.p.novalon.cn/(页面在根路径)。改绝对路径会把子域首页变成 /novavis/
- 故用 4 条 prefix rewrite 把根命名空间映射进子目录,而非改写 HTML
四道门禁(从 authority 的四个 python 脚本移植为 Playwright,已并入 test:all):
- e2e/landing/{layout,motion,demo,a11y}.spec.ts + 独立 config(单引擎单 project 串行)
- layout:几何与焦点 / motion:js-grow 渐进生长与 reduced-motion 直达终态
- demo:首屏剧本四步 + 徽标一一对应 + 无 JS 降级四层真实可见性
- a11y:结构与全量对比度(同色无条件阻断)+ axe critical/serious=0
- 实测 13 passed / EXIT=0(1.4m)
补一个映射期暴露的真缺陷:landing 的 main.js 固定 POST /api/v1/contact 且只认
code===200,而本仓只有 /api/contact(formData + 必填 subject),镜像侧转化路径
一直 404。新增 src/app/api/v1/contact/route.ts 按 authority 契约响应(JSON +
{code:200}),而非改前端去适配本仓——改前端等于把适配成本转嫁给子域,且会让
两个落点的成功判据不一致。9 个单测覆盖校验、限流、上游失败不透传 5xx。
文档与配置同步:CLAUDE.md → AGENTS.md(单文档真源)、docs/landing.md、
docs/deployment.md §八、ADR-0014、qa-tracker §32、README 与 quality-gates 脚本表、
Jenkinsfile 落地「♿ 可访问性门禁」阶段的 landing 四道门禁、eslint 忽略
.next-dev-live 构建产物目录(未忽略时 eslint . 会扫出 21195 errors)。
门禁:tsc 0 / eslint 0 / jest app/api/v1 9/9 / test:landing 13 passed。
175 lines
11 KiB
JavaScript
175 lines
11 KiB
JavaScript
import { withSentryConfig } from '@sentry/nextjs';
|
||
|
||
const cdnDomain = process.env.CDN_DOMAIN || '';
|
||
|
||
/**
|
||
* Sentry 客户端 DSN → CSP 放行域。
|
||
* 为什么必须在此处理:CSP 是本站安全响应的唯一来源(见下方 APP_SECURITY_HEADERS),
|
||
* 若不给 DSN 的 ingest 域开 connect-src,浏览器会在 SDK 发 envelope 时直接拦截,
|
||
* "接线成功但上报被 CSP 拦死"(2026-09-23 验收 final-verdict §4.3 的前置缺口)。
|
||
* 做法:仅当 NEXT_PUBLIC_SENTRY_DSN 存在时,从其 URL 中取 protocol//host 追加进 connect-src;
|
||
* DSN 缺失时 CSP 与接线前逐字节一致(与 GA/监控一致的"无配置即惰性"约定)。
|
||
* worker-src 'self' blob: 亦仅在 Sentry 启用时追加:replayIntegration 以
|
||
* URL.createObjectURL 生成的 blob worker 运行(证据:
|
||
* node_modules/@sentry/replay/build/npm/esm/index.js:5221、5637 `new Worker(workerUrl)`),
|
||
* 默认 worker-src 回落到 default-src 'self' 会拦截 blob:。
|
||
*/
|
||
const sentryPublicDsn = process.env.NEXT_PUBLIC_SENTRY_DSN || '';
|
||
let sentryConnectSrcExtra = '';
|
||
let sentryWorkerSrcExtra = '';
|
||
if (sentryPublicDsn) {
|
||
try {
|
||
const dsnUrl = new URL(sentryPublicDsn);
|
||
sentryConnectSrcExtra = ` ${dsnUrl.protocol}//${dsnUrl.host}`;
|
||
sentryWorkerSrcExtra = " worker-src 'self' blob:;";
|
||
} catch {
|
||
console.warn('[next.config] NEXT_PUBLIC_SENTRY_DSN 不是合法 URL,CSP 未追加 Sentry 放行域');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* dev-only 的 `unsafe-eval`:React 在**开发模式**需要 eval()(DevTools 调用栈重建等调试特性),
|
||
* 而本应用的 CSP 由这里统一下发 ⇒ dev 下每页控制台都报
|
||
* 「eval() is not supported in this environment…React requires eval() in development mode」。
|
||
* 生产 React 从不使用 eval ⇒ 生产头部必须与此前逐字节一致(CSP 单一真源纪律),
|
||
* 故只在 NODE_ENV !== 'production'(即 `next dev`)时追加。
|
||
* `next build` / `next start` / standalone server.js 均为 production ⇒ 不受影响。
|
||
*/
|
||
const isDevServer = process.env.NODE_ENV !== 'production';
|
||
const scriptSrcExtra = isDevServer ? " 'unsafe-eval'" : '';
|
||
|
||
|
||
/**
|
||
* 应用层安全响应头的唯一来源(single source of truth)。
|
||
*
|
||
* 为什么放在这里而不是 nginx:standalone 产物由 `node dist/standalone/server.js` 提供服务,
|
||
* 同一份构建会在 nginx 之后、纯 Node、本地 `next start` 等环境下给出完全一致的头部;
|
||
* 也避免了两层各自 add_header 造成的重复值(历史缺陷:浏览器收到
|
||
* `X-Frame-Options: DENY, SAMEORIGIN` 这类非法的重复/互斥值)。
|
||
* 覆盖面(官方文档 headers.md):'Headers are checked before the filesystem which includes
|
||
* pages and /public files.' ⇒ 连 public/uploads/* 也会拿到本数组,无需边缘重复声明。
|
||
*
|
||
* 分工约定(改头部前先对齐):
|
||
* - next.config.mjs(本数组):随应用版本演进的文档级头部 —— CSP / XFO / nosniff /
|
||
* Referrer-Policy / Permissions-Policy / X-XSS-Protection / X-DNS-Prefetch-Control。
|
||
* - nginx(nginx-static*.conf):只保留 TLS 与 301、HSTS(Next 不设,且只有终结 TLS 的
|
||
* 边缘知道协议与证书状态)、gzip、limit_req,以及 /uploads/ 的落盘加固(见下)。
|
||
* - 例外:/uploads/ 在 nginx-static-production.conf 中由磁盘直供、Next 不参与应答,
|
||
* 故该 location 块必须自行声明 nosniff 与 sandbox CSP;这不属于跨层重复。
|
||
*/
|
||
const APP_SECURITY_HEADERS = [
|
||
{ key: 'X-Content-Type-Options', value: 'nosniff' },
|
||
// DENY(而非 nginx 曾设置的 SAMEORIGIN):全仓无以 iframe 嵌入本站页面的用例
|
||
// ——src 内所有 iframe 命中都在 src/lib/sanitize.ts 的剔除名单及其测试里(语义为“禁止 iframe”),
|
||
// e2e 目录零 iframe 引用,管理后台也不以同源 iframe 嵌入任何页面;取更严格值不破坏现有功能。
|
||
{ key: 'X-Frame-Options', value: 'DENY' },
|
||
{ key: 'X-XSS-Protection', value: '1; mode=block' },
|
||
{ key: 'Referrer-Policy', value: 'strict-origin-when-cross-origin' },
|
||
{
|
||
key: 'Content-Security-Policy',
|
||
// Sentry 扩展位(sentryConnectSrcExtra / sentryWorkerSrcExtra)仅在有 NEXT_PUBLIC_SENTRY_DSN 时非空,
|
||
// 其余内容与收紧前逐字节一致(见文件头 APP_SECURITY_HEADERS 注释与 Sentry DSN 段落)。
|
||
value: `default-src 'self'; script-src 'self' 'unsafe-inline'${scriptSrcExtra} https://www.googletagmanager.com https://ssl.google-analytics.com; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob: https://www.google-analytics.com https://ssl.google-analytics.com https://www.googletagmanager.com; font-src 'self'; connect-src 'self' https://www.google-analytics.com https://ssl.google-analytics.com https://www.googletagmanager.com${sentryConnectSrcExtra}; frame-src 'self'; object-src 'none'; base-uri 'self'; form-action 'self';${sentryWorkerSrcExtra}`,
|
||
},
|
||
{ key: 'Permissions-Policy', value: 'camera=(), microphone=(), geolocation=(), interest-cohort=()' },
|
||
// 原由 nginx-static.conf 设置;移入应用层,使无 nginx 的环境也带上(Next 官方文档
|
||
// 即以 headers() 设置此头:node_modules/next/dist/docs/.../next-config-js/headers.md)。
|
||
{ key: 'X-DNS-Prefetch-Control', value: 'on' },
|
||
];
|
||
|
||
const nextConfig = {
|
||
// 部署层必须按 standalone 契约服务:`node dist/standalone/server.js` + HOSTNAME=0.0.0.0,
|
||
// 并把 dist/static 拷到 <standalone>/<distDir>/static、public 拷到 <standalone>/public
|
||
// (Next 官方 output 文档:minimal server 默认不带 public 与 static)。
|
||
// 见 Dockerfile / Dockerfile.prod;不要把 dist/ 当作静态 HTML 根交给 nginx。
|
||
output: 'standalone',
|
||
// 默认 dist/;可用 NEXT_DIST_DIR 覆盖(CI 分环境输出,或本地需要避开既有构建产物)
|
||
distDir: process.env.NEXT_DIST_DIR || 'dist',
|
||
assetPrefix: cdnDomain || undefined,
|
||
images: {
|
||
// 关闭 Next 的图片优化(/_next/image 代理 + 服务端重编码),图片以原文件分发。
|
||
// 真实原因(与 output 模式无关,standalone 下同样成立):
|
||
// 1. 图片以 CDN 分发为主(assetPrefix 由 CDN_DOMAIN 驱动,见 docs/CDN_CONFIGURATION.md),
|
||
// 优化端点的收益被 CDN 抵消;
|
||
// 2. /_next/image 会替换上游响应,/uploads/ 与 CDN 侧的缓存/Content-Disposition 语义需另行处理。
|
||
// 与 sharp 无关:本项目在 src/lib/media/image-processor.ts 里直接用 sharp 生成缩略图/derivative,
|
||
// 无论本项取何值都需要 musl 平台二进制(见 Dockerfile.prod 的 sharp-deps 阶段)。
|
||
// 若要改为 false:必须同时确认所有环境都有 Node 运行时接管 /_next/image(否则图片 404),
|
||
// 并复核 CDN 回源规则。该改动影响图片服务链路与带宽,属部署决策,勿顺手改。
|
||
unoptimized: true,
|
||
// 注:此处曾声明 formats: ['image/avif', 'image/webp']。unoptimized 为 true 时该字段
|
||
// 不参与产物生成(死配置),已移除;恢复图片优化时再按需加回。
|
||
},
|
||
compress: true,
|
||
poweredByHeader: false,
|
||
reactStrictMode: true,
|
||
experimental: {
|
||
optimizePackageImports: ['lucide-react', 'framer-motion'],
|
||
},
|
||
compiler: {
|
||
removeConsole: process.env.NODE_ENV === 'production',
|
||
},
|
||
generateEtags: true,
|
||
httpAgentOptions: {
|
||
keepAlive: true,
|
||
},
|
||
async rewrites() {
|
||
return [
|
||
// ========================================================================
|
||
// 睿视 NovaVis landing(2026-12-03 起由**本仓**统一管理,authority 已退役该目录)
|
||
//
|
||
// 物理布局:`public/novavis/{index.html,css,js,assets,images/logos}` 一棵树自成一体。
|
||
// URL 契约:**保持源站形态不变** —— 页面引用仍是 `/css/style.css`、`/js/main.js`、
|
||
// `/assets/*`、`/images/logos/*` 这些站点级绝对路径。
|
||
//
|
||
// 为什么 URL 不能改:同一份字节要服务两个落点 ——
|
||
// ① 官网镜像 `novalon.cn/novavis/`(本仓 Next public 层);
|
||
// ② 独立子域 `novavis.p.novalon.cn/`(nginx `root /var/www/novavis-landing`,
|
||
// 页面在**根路径**)。改 HTML 为 `/novavis/...` 会把子域首页变成
|
||
// `novavis.p.novalon.cn/novavis/`,产品站首页带路径不可接受。
|
||
//
|
||
// 于是用 4 条 prefix rewrite 把根命名空间映射进子目录(ADR-0014 §4 的
|
||
// 「子目录化 + rewrites 前缀映射」模式,由此回溯到睿视)。根 `public/{css,js,assets,
|
||
// images/logos}` 已删除 ⇒ 这四条是这些前缀的**唯一**占用者,无歧义。
|
||
// 子域发布时把 `public/novavis/{css,js,assets,images}` 平铺到宿主目录根,URL 零变化。
|
||
//
|
||
// 入口 `/novavis` 单条:Next 的 public 文件层不做目录 → index.html 补全
|
||
// (实测 `/novavis/` 308 → `/novavis` → 404),故用 rewrite 补齐。
|
||
// landing 零内联脚本(唯一 script 为同源 /js/main.js)+ 4 处内联 style 属性,
|
||
// 生产 CSP(script-src 'self' + style-src 'self' 'unsafe-inline')实测放行。
|
||
// ========================================================================
|
||
{ source: '/novavis', destination: '/novavis/index.html' },
|
||
{ source: '/css/:path*', destination: '/novavis/css/:path*' },
|
||
{ source: '/js/:path*', destination: '/novavis/js/:path*' },
|
||
{ source: '/assets/:path*', destination: '/novavis/assets/:path*' },
|
||
{ source: '/images/logos/:path*', destination: '/novavis/images/logos/:path*' },
|
||
];
|
||
},
|
||
async headers() {
|
||
return [
|
||
{
|
||
source: '/(.*)',
|
||
headers: APP_SECURITY_HEADERS,
|
||
},
|
||
];
|
||
},
|
||
};
|
||
|
||
/**
|
||
* withSentryConfig 包装(@sentry/nextjs 10.67.0,导出见
|
||
* node_modules/@sentry/nextjs/build/types/index.types.d.ts:27)。它是构建期接线的唯一入口:
|
||
* - Turbopack 路径(Next 16 默认 bundler,node_modules/next/dist/docs/01-app/02-guides/upgrading/version-16.md:128):
|
||
* 向 instrumentation 与 instrumentation-client 两个入口文件注入 value-injection 规则
|
||
* (node_modules/@sentry/nextjs/build/esm/config/turbopack/generateValueInjectionRules.js:34、49)、
|
||
* compiler.runAfterProductionCompile(sourcemaps/发布管理)与 productionBrowserSourceMaps:true
|
||
* (getFinalConfigObjectBundlerUtils.js:47-120)。
|
||
* - 只在 bundler 判定为 webpack 时才追加 custom webpack 键(getFinalConfigObjectBundlerUtils.js:157-159),
|
||
* 不会触发 Next 16 "Turbopack 构建遇到 webpack 配置即失败" 的保护(version-16.md:154)。
|
||
* - 未设 SENTRY_AUTH_TOKEN 时发布/sourcemap 上传仅告警跳过,不会红构建
|
||
* (node_modules/@sentry/bundler-plugin-core/dist/cjs/index.js:5743、5992);
|
||
* 是否启用上传属部署决策,本轮不额外传 options。
|
||
* 运行时初始化入口在 src/instrumentation.ts(server/edge)与 src/instrumentation-client.ts(browser),
|
||
* 无 DSN 时全部惰性(见文件头 Sentry 段落与 sentry.*.config.ts 的 if (SENTRY_DSN) 门禁)。
|
||
*/
|
||
export default withSentryConfig(nextConfig);
|