-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnext.config.ts
More file actions
78 lines (68 loc) · 2.32 KB
/
Copy pathnext.config.ts
File metadata and controls
78 lines (68 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
import createMDX from "@next/mdx";
import type { NextConfig } from "next";
const appDir = path.dirname(fileURLToPath(import.meta.url));
/** Parent of both checkouts when zigeditor is linked from outside this app. */
function outsidePackageRoot(): string | undefined {
try {
const real = fs.realpathSync(path.join(appDir, "node_modules", "zigeditor"));
const inside = real === appDir || real.startsWith(appDir + path.sep);
if (inside) return undefined;
const appParts = appDir.split(path.sep);
const pkgParts = real.split(path.sep);
const shared: string[] = [];
for (let i = 0; i < Math.min(appParts.length, pkgParts.length); i++) {
if (appParts[i] !== pkgParts[i]) break;
shared.push(appParts[i]);
}
const root = shared.join(path.sep);
return root.length > 0 ? root : undefined;
} catch {
return undefined;
}
}
const linkedRoot = outsidePackageRoot();
function contentSecurityPolicy() {
const isDev = process.env.NODE_ENV === "development";
// Header-based CSP (no nonce): production keeps 'unsafe-inline' so Next.js can boot.
return [
"default-src 'self'",
`script-src 'self' 'unsafe-inline' 'wasm-unsafe-eval'${isDev ? " 'unsafe-eval'" : ""}`,
"style-src 'self' 'unsafe-inline'",
"img-src 'self' blob: data:",
"font-src 'self'",
`connect-src 'self'${isDev ? " ws: wss:" : ""}`,
"worker-src 'self' blob:",
"frame-src https://www.youtube-nocookie.com",
"object-src 'none'",
"base-uri 'self'",
"form-action 'self'",
"frame-ancestors 'none'",
].join("; ");
}
const nextConfig: NextConfig = {
// A sibling link lives outside this app. Turbopack will not read its CSS
// until the root covers both checkouts. A normal install stays inside
// node_modules, so a ZigLab-only deploy leaves this unset.
...(linkedRoot ? { turbopack: { root: linkedRoot } } : {}),
pageExtensions: ["js", "jsx", "md", "mdx", "ts", "tsx"],
async headers() {
return [
{
source: "/:path*",
headers: [
{
key: "Content-Security-Policy",
value: contentSecurityPolicy(),
},
],
},
];
},
};
const withMDX = createMDX({
extension: /\.mdx?$/,
});
export default withMDX(nextConfig);