-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnext.config.ts
More file actions
202 lines (187 loc) · 5.84 KB
/
Copy pathnext.config.ts
File metadata and controls
202 lines (187 loc) · 5.84 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
import type { NextConfig } from "next";
import { withSentryConfig } from "@sentry/nextjs";
const nextConfig: NextConfig = {
// Vercel deployment optimization
output: process.env.VERCEL ? 'standalone' : undefined,
poweredByHeader: false,
reactStrictMode: true,
// Vercel-specific optimizations
...(process.env.VERCEL && {
// Enable static exports for better caching
trailingSlash: false,
}),
// Server external packages (moved from experimental)
serverExternalPackages: ['@prisma/client', 'bcryptjs'],
// Image optimization
images: {
formats: ['image/webp', 'image/avif'],
minimumCacheTTL: 3600,
dangerouslyAllowSVG: false,
contentSecurityPolicy: "default-src 'self'; script-src 'none'; sandbox;",
remotePatterns: [
{
protocol: 'https',
hostname: 'images.unsplash.com',
port: '',
pathname: '/**',
},
{
protocol: 'https',
hostname: 'unsplash.com',
port: '',
pathname: '/**',
},
// Add your production CDN/storage domains
{
protocol: 'https',
hostname: '**.amazonaws.com',
port: '',
pathname: '/**',
},
{
protocol: 'https',
hostname: '**.cloudinary.com',
port: '',
pathname: '/**',
},
// Supabase storage
{
protocol: 'https',
hostname: '**.supabase.co',
port: '',
pathname: '/storage/**',
},
],
},
// Security headers
headers: async () => [
{
source: '/(.*)',
headers: [
{
key: 'X-Frame-Options',
value: 'SAMEORIGIN',
},
{
key: 'X-Content-Type-Options',
value: 'nosniff',
},
{
key: 'X-XSS-Protection',
value: '1; mode=block',
},
{
key: 'Referrer-Policy',
value: 'strict-origin-when-cross-origin',
},
{
key: 'Permissions-Policy',
value: 'camera=(), microphone=(), geolocation=()',
},
{
key: 'Content-Security-Policy',
value: [
"default-src 'self'",
// Script sources: includes Sandpack bundler and esm.sh for npm packages
"script-src 'self' 'unsafe-inline' 'unsafe-eval' https://www.google-analytics.com https://cdn.jsdelivr.net https://unpkg.com https://cdnjs.cloudflare.com https://va.vercel-scripts.com https://*.codesandbox.io https://esm.sh",
"style-src 'self' 'unsafe-inline' https://fonts.googleapis.com https://cdn.jsdelivr.net",
"img-src 'self' data: blob: https:",
"font-src 'self' https://fonts.gstatic.com",
// Connect sources: includes Sandpack bundler, esm.sh, and npm registry for dependency resolution
"connect-src 'self' https://www.google-analytics.com https://cdn.jsdelivr.net https://unpkg.com https://cdnjs.cloudflare.com https://va.vercel-scripts.com https://*.codesandbox.io https://esm.sh https://registry.npmjs.org https://esm.run https://*.supabase.co https://*.ingest.sentry.io https://*.ingest.us.sentry.io",
// Frame sources: Sandpack preview iframe + YouTube embeds
"frame-src 'self' https://*.codesandbox.io https://www.youtube-nocookie.com https://www.youtube.com",
"media-src 'self' blob:",
"worker-src 'self' blob:",
"object-src 'none'",
"base-uri 'self'",
"frame-ancestors 'self'",
"form-action 'self'",
"upgrade-insecure-requests"
].join('; '),
},
{
key: 'Strict-Transport-Security',
value: 'max-age=31536000; includeSubDomains; preload',
},
],
},
{
source: '/api/:path*',
headers: [
{
key: 'Access-Control-Allow-Origin',
value: process.env.CORS_ORIGINS || 'https://bcs-etextbook.vercel.app',
},
{
key: 'Access-Control-Allow-Methods',
value: 'GET, POST, PUT, DELETE, OPTIONS',
},
{
key: 'Access-Control-Allow-Headers',
value: 'Content-Type, Authorization',
},
{
key: 'X-RateLimit-Limit',
value: process.env.RATE_LIMIT_REQUESTS || '100',
},
],
},
],
// Production redirects
redirects: async () => [
// Force HTTPS in production
...(process.env.NODE_ENV === 'production' && process.env.FORCE_HTTPS === 'true' ? [
{
source: '/:path*',
has: [
{
type: 'header',
key: 'x-forwarded-proto',
value: 'http',
},
],
destination: 'https://bcs-etextbook.vercel.app/:path*',
permanent: true,
},
] : []),
],
// Compression and caching
compress: true,
// Bundle analyzer in development
...(process.env.ANALYZE === 'true' && {
webpack: (config: any) => {
config.plugins.push(
new (require('@next/bundle-analyzer')({ enabled: true }))()
);
return config;
},
}),
// Logging configuration
logging: {
fetches: {
fullUrl: process.env.NODE_ENV === 'development',
},
},
// Experimental features for production
experimental: {
// Note: optimizeCss removed due to critters dependency issues
// Can be re-enabled once the issue is resolved
},
};
export default withSentryConfig(nextConfig, {
// Sentry webpack plugin options
org: process.env.SENTRY_ORG,
project: process.env.SENTRY_PROJECT,
authToken: process.env.SENTRY_AUTH_TOKEN,
// Suppress source map upload logs in build output
silent: true,
// Upload larger set of source maps for better stack traces
widenClientFileUpload: true,
// Hide source maps from client bundles
sourcemaps: {
deleteSourcemapsAfterUpload: true,
},
// Tree-shake Sentry logger statements to reduce bundle size
disableLogger: true,
});