Repository navigation
Expand file tree
/
Copy pathnext.config.ts
More file actions
103 lines (95 loc) · 3.01 KB
/
Copy pathnext.config.ts
File metadata and controls
103 lines (95 loc) · 3.01 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import type { NextConfig } from "next";
const isProd = process.env.NODE_ENV === "production";
function originOf(value?: string | null) {
if (!value) return [];
try {
const origin = new URL(value).origin;
if (origin.includes("[") || origin.includes("::")) return [];
if (isProd && /^https?:\/\/(localhost|127\.0\.0\.1)(:|$)/i.test(origin)) return [];
return [origin];
} catch {
return [];
}
}
const hostedCrm =
process.env.NEXT_PUBLIC_SERVER_CRM_API_URL ||
process.env.CRM_SERVER_API_URL ||
"https://indonor-tech.onrender.com/api/v1";
const crmApiOrigins = isProd
? originOf(hostedCrm)
: [
...originOf(process.env.NEXT_PUBLIC_LOCAL_CRM_API_URL || "http://127.0.0.1:5000/api/v1"),
"http://127.0.0.1:5000",
"http://localhost:5000",
];
const allowedCrmOrigins = [...new Set(crmApiOrigins.filter(Boolean))].join(" ");
const contentSecurityPolicy = [
"default-src 'self'",
"base-uri 'self'",
"form-action 'self'",
"frame-ancestors 'none'",
"object-src 'none'",
`img-src 'self' data: blob: https: ${allowedCrmOrigins}`.trim(),
"font-src 'self' data: https://fonts.gstatic.com",
"style-src 'self' 'unsafe-inline' https://fonts.googleapis.com",
"script-src 'self' 'unsafe-inline' 'unsafe-eval'",
`connect-src 'self' https: ${allowedCrmOrigins}`.trim(),
"frame-src 'self' https://www.google.com https://maps.google.com https://www.youtube-nocookie.com https://www.youtube.com https://player.vimeo.com",
`media-src 'self' blob: https: ${allowedCrmOrigins}`.trim(),
...(isProd ? ["upgrade-insecure-requests"] : []),
].join("; ");
const securityHeaders = [
{ key: "X-DNS-Prefetch-Control", value: "on" },
{ key: "X-Frame-Options", value: "DENY" },
{ key: "X-Content-Type-Options", value: "nosniff" },
{ key: "Referrer-Policy", value: "strict-origin-when-cross-origin" },
{
key: "Permissions-Policy",
value: "camera=(), microphone=(), geolocation=(), payment=(), usb=(), interest-cohort=()",
},
{ key: "X-Permitted-Cross-Domain-Policies", value: "none" },
{ key: "Cross-Origin-Opener-Policy", value: "same-origin" },
{ key: "Content-Security-Policy", value: contentSecurityPolicy },
...(isProd
? [
{
key: "Strict-Transport-Security",
value: "max-age=63072000; includeSubDomains; preload",
},
]
: []),
];
const nextConfig: NextConfig = {
reactCompiler: true,
poweredByHeader: false,
compress: true,
experimental: {
turbopackUseSystemTlsCerts: true,
},
images: {
formats: ["image/avif", "image/webp"],
dangerouslyAllowSVG: false,
},
async headers() {
return [
{
source: "/:path*",
headers: securityHeaders,
},
{
source: "/llms.txt",
headers: [
{
key: "Content-Type",
value: "text/plain; charset=utf-8",
},
{
key: "Cache-Control",
value: "public, max-age=86400, stale-while-revalidate=604800",
},
],
},
];
},
};
export default nextConfig;