-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnext.config.ts
More file actions
116 lines (108 loc) · 2.94 KB
/
next.config.ts
File metadata and controls
116 lines (108 loc) · 2.94 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
import type { NextConfig } from 'next';
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL;
function getOrigin(value: string | undefined): string | null {
if (!value) {
return null;
}
try {
return new URL(value).origin;
} catch {
return null;
}
}
const connectSources = [
"'self'",
getOrigin(supabaseUrl),
'https://api.stripe.com',
'https://checkout.stripe.com',
'https://*.api.sanity.io',
'https://*.apicdn.sanity.io',
process.env.NODE_ENV === 'production' ? null : 'ws:',
process.env.NODE_ENV === 'production' ? null : 'wss:',
].filter(Boolean) as string[];
const scriptSources = [
"'self'",
"'unsafe-inline'",
'https://js.stripe.com',
process.env.NODE_ENV === 'production' ? null : "'unsafe-eval'",
].filter(Boolean) as string[];
const contentSecurityPolicy = [
"default-src 'self'",
"base-uri 'self'",
"frame-ancestors 'none'",
"form-action 'self'",
`script-src ${scriptSources.join(' ')}`,
`script-src-elem ${scriptSources.join(' ')}`,
"style-src 'self' 'unsafe-inline'",
"img-src 'self' data: blob: https://cdn.sanity.io https://*.supabase.co",
`connect-src ${connectSources.join(' ')}`,
"font-src 'self' data:",
"frame-src 'self' https://checkout.stripe.com https://js.stripe.com",
"manifest-src 'self'",
"worker-src 'self' blob:",
"object-src 'none'",
process.env.NODE_ENV === 'production' ? 'upgrade-insecure-requests' : null,
]
.filter(Boolean)
.join('; ');
const nextConfig: NextConfig = {
allowedDevOrigins: ['http://127.0.0.1:3000', 'http://localhost:3000'],
env: {
NEXT_PUBLIC_SANITY_PROJECT_ID:
process.env.NEXT_PUBLIC_SANITY_PROJECT_ID ??
process.env.SANITY_PROJECT_ID ??
'',
NEXT_PUBLIC_SANITY_DATASET:
process.env.NEXT_PUBLIC_SANITY_DATASET ?? process.env.SANITY_DATASET ?? '',
},
images: {
remotePatterns: [
{
protocol: 'https',
hostname: 'cdn.sanity.io',
},
{
protocol: 'https',
hostname: '**.supabase.co',
pathname: '/storage/v1/object/public/**',
},
],
},
async headers() {
return [
{
source: '/(.*)',
headers: [
{
key: 'Content-Security-Policy',
value: contentSecurityPolicy,
},
{
key: 'Referrer-Policy',
value: 'strict-origin-when-cross-origin',
},
{
key: 'Strict-Transport-Security',
value:
process.env.NODE_ENV === 'production'
? 'max-age=31536000; includeSubDomains; preload'
: 'max-age=0',
},
{
key: 'X-Content-Type-Options',
value: 'nosniff',
},
{
key: 'X-Frame-Options',
value: 'DENY',
},
{
key: 'Permissions-Policy',
value: 'camera=(), microphone=(), geolocation=()',
},
],
},
];
},
};
export default nextConfig;