-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnext.config.mjs
More file actions
180 lines (170 loc) · 5.23 KB
/
next.config.mjs
File metadata and controls
180 lines (170 loc) · 5.23 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
import bundleAnalyzer from '@next/bundle-analyzer'
const withBundleAnalyzer = bundleAnalyzer({
enabled: process.env.ANALYZE === 'true',
})
/** @type {import('next').NextConfig} */
const nextConfig = {
typescript: {
ignoreBuildErrors: false,
},
images: {
unoptimized: true,
},
// Increase body size limit for API routes (for email attachments)
experimental: {
esmExternals: true,
},
// Fix ChunkLoadError issues and handle MJML server-side only
webpack: (config, { dev, isServer }) => {
// Exclude MJML and related packages from client-side bundle
if (!isServer) {
config.resolve.fallback = {
...config.resolve.fallback,
fs: false,
path: false,
crypto: false,
stream: false,
util: false,
os: false,
};
config.externals = [
...(config.externals || []),
'mjml',
'mjml-core',
'clean-css',
'html-minifier',
];
}
// Suppress MJML webpack warnings
config.ignoreWarnings = [
...(config.ignoreWarnings || []),
{ module: /mjml/ },
{ message: /Critical dependency: the request of a dependency is an expression/ },
];
if (dev && !isServer) {
config.optimization = {
...config.optimization,
splitChunks: {
...config.optimization.splitChunks,
cacheGroups: {
...config.optimization.splitChunks.cacheGroups,
default: false,
vendors: false,
// Create a single vendor chunk
vendor: {
name: 'vendors',
chunks: 'all',
test: /[\\/]node_modules[\\/]/,
priority: 20,
reuseExistingChunk: true,
},
// Create a commons chunk
common: {
name: 'commons',
chunks: 'all',
minChunks: 2,
priority: 10,
reuseExistingChunk: true,
},
},
},
}
}
return config
},
// Server-side configuration for larger payloads
serverExternalPackages: ['mjml'],
// Increase body parser size limit for API routes
// Add headers for CORS and content-type handling
// SECURITY: Restrict CORS to specific origins in production
async headers() {
// Get allowed origins from environment or use defaults
const allowedOrigins = process.env.ALLOWED_ORIGINS
? process.env.ALLOWED_ORIGINS.split(',')
: ['http://localhost:3000', 'http://localhost:3001']
// In production, use the actual domain
const origin = process.env.NODE_ENV === 'production'
? (process.env.NEXT_PUBLIC_APP_URL || 'https://echomail.adityamer.live')
: allowedOrigins[0]
return [
{
source: '/api/:path*',
headers: [
{
key: 'Access-Control-Allow-Origin',
value: origin,
},
{
key: 'Access-Control-Allow-Methods',
value: 'GET, POST, PUT, DELETE, OPTIONS',
},
{
key: 'Access-Control-Allow-Headers',
value: 'Content-Type, Authorization, X-CSRF-Token',
},
{
key: 'Access-Control-Allow-Credentials',
value: 'true',
},
// Security headers
{
key: 'X-Content-Type-Options',
value: 'nosniff',
},
{
key: 'X-Frame-Options',
value: 'DENY',
},
{
key: 'X-XSS-Protection',
value: '1; mode=block',
},
],
},
// Additional security headers for all routes
{
source: '/:path*',
headers: [
{
key: 'X-Content-Type-Options',
value: 'nosniff',
},
{
key: 'Referrer-Policy',
value: 'strict-origin-when-cross-origin',
},
// Content Security Policy
{
key: 'Content-Security-Policy',
value: [
"default-src 'self'",
"script-src 'self' 'unsafe-inline' 'unsafe-eval' https://accounts.google.com https://apis.google.com",
"style-src 'self' 'unsafe-inline' https://fonts.googleapis.com",
"font-src 'self' https://fonts.gstatic.com",
"img-src 'self' data: blob: https: http:",
"connect-src 'self' https://accounts.google.com https://oauth2.googleapis.com https://www.googleapis.com https://gmail.googleapis.com https://*.appwrite.io wss://*.appwrite.io",
"frame-src 'self' https://accounts.google.com",
"object-src 'none'",
"base-uri 'self'",
"form-action 'self'",
"frame-ancestors 'none'",
"upgrade-insecure-requests",
].join('; '),
},
// Permissions Policy
{
key: 'Permissions-Policy',
value: 'camera=(), microphone=(), geolocation=(), interest-cohort=()',
},
// Strict Transport Security (HSTS)
{
key: 'Strict-Transport-Security',
value: 'max-age=31536000; includeSubDomains',
},
],
},
]
},
turbopack: {},
}
export default withBundleAnalyzer(nextConfig)