-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnext.config.ts
More file actions
152 lines (145 loc) · 4.41 KB
/
Copy pathnext.config.ts
File metadata and controls
152 lines (145 loc) · 4.41 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import type { NextConfig } from "next";
import bundleAnalyzer from "@next/bundle-analyzer";
const withBundleAnalyzer = bundleAnalyzer({
enabled: process.env.ANALYZE === "true",
});
const isDev = process.env.NODE_ENV === "development";
// CSP is only sent in production builds (see headers() below). Third-party
// checkout widgets must be allowlisted explicitly — default-src 'self' blocks
// their scripts/iframes/fetches when frame-src/connect-src are omitted.
// Turnstile: https://developers.cloudflare.com/turnstile/reference/content-security-policy/
const cspHeader = `
default-src 'self';
script-src 'self' 'unsafe-eval' 'unsafe-inline' https://challenges.cloudflare.com https://js.stripe.com https://va.vercel-scripts.com;
style-src 'self' 'unsafe-inline' https://challenges.cloudflare.com;
img-src 'self' blob: data: https:;
font-src 'self' data:;
connect-src 'self' https://challenges.cloudflare.com https://api.stripe.com https://vitals.vercel-insights.com;
frame-src 'self' https://challenges.cloudflare.com https://js.stripe.com https://hooks.stripe.com;
object-src 'none';
base-uri 'self';
form-action 'self';
frame-ancestors 'none';
upgrade-insecure-requests;
`;
const requiredEnvVars = [
"DATABASE_URL",
"JWT_SECRET",
"NEXT_PUBLIC_SUPABASE_URL",
"NEXT_PUBLIC_SUPABASE_ANON_KEY",
];
for (const envVar of requiredEnvVars) {
if (!process.env[envVar]) {
throw new Error(
`Missing required environment variable: ${envVar}\n` +
`Make sure it's set in your .env.local or deployment environment.`,
);
}
}
const nextConfig: NextConfig = {
reactStrictMode: true,
images: {
qualities: [25, 50, 75, 100],
},
cacheComponents: false,
reactCompiler: true,
typedRoutes: true,
experimental: {
typedEnv: true,
serverActions: {
bodySizeLimit: "50mb",
},
},
turbopack: {
resolveAlias: {
canvas: "./empty-module.ts",
},
},
typescript: {
ignoreBuildErrors: false,
},
compiler: {
styledComponents: false,
},
...(isDev
? {}
: {
async headers() {
return [
{
source: "/(.*)",
headers: [
{
key: "Content-Security-Policy",
value: cspHeader.replace(/\n/g, "").trim(),
},
{
key: "X-DNS-Prefetch-Control",
value: "on",
},
{
key: "X-Content-Type-Options",
value: "nosniff",
},
{
key: "X-Frame-Options",
value: "DENY",
},
{
key: "Referrer-Policy",
value: "strict-origin-when-cross-origin",
},
{
key: "Permissions-Policy",
value:
"geolocation=(), microphone=(), camera=(), payment=(), usb=(), accelerometer=(), gyroscope=(), magnetometer=()",
},
{
key: "Cross-Origin-Embedder-Policy",
value: "credentialless",
},
{
key: "Cross-Origin-Opener-Policy",
value: "same-origin",
},
{
key: "Cross-Origin-Resource-Policy",
value: "same-origin",
},
{
key: "X-Permitted-Cross-Domain-Policies",
value: "none",
},
{
key: "Strict-Transport-Security",
value: "max-age=31536000; includeSubDomains; preload",
},
],
},
{
source: "/sw.js",
headers: [
{
key: "Service-Worker-Allowed",
value: "/",
},
{
key: "Cache-Control",
value: "public, max-age=0, must-revalidate",
},
],
},
{
source: "/:path*\\.(ico|png|jpg|jpeg|gif|webp|svg|css|js)",
headers: [
{
key: "Cache-Control",
value: "public, max-age=31536000, immutable",
},
],
},
];
},
}),
};
export default withBundleAnalyzer(nextConfig);