-
-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathnext.config.js
More file actions
176 lines (162 loc) · 6.72 KB
/
next.config.js
File metadata and controls
176 lines (162 loc) · 6.72 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
/** @type {import('next').NextConfig} */
const withPWA = require("next-pwa")({
dest: "public",
disable: process.env.NODE_ENV === "development",
register: true,
skipWaiting: true,
runtimeCaching: require("next-pwa/cache"),
buildExcludes: [
/middleware-manifest\.json$/,
/middleware-runtime\.js$/,
/_middleware\.js$/,
/^.+\\_middleware\.js$/,
],
publicExcludes: ["!robots.txt"],
fallbacks: {
document: "/_offline",
},
});
const nextConfig = {
reactStrictMode: true,
experimental: {},
// Security Headers
async headers() {
return [
{
// Apply security headers to all routes
source: "/:path*",
headers: [
{
key: "X-DNS-Prefetch-Control",
value: "on",
},
{
key: "Strict-Transport-Security",
value: "max-age=63072000; includeSubDomains; preload",
},
{
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=(), interest-cohort=()",
},
{
key: "Content-Security-Policy",
value: [
"default-src 'self'",
"script-src 'self' 'unsafe-eval' 'unsafe-inline' https://www.clarity.ms https://va.vercel-scripts.com https://www.googletagmanager.com https://maps.googleapis.com https://pro.fontawesome.com https://cdn.jsdelivr.net",
"style-src 'self' 'unsafe-inline' https://fonts.googleapis.com https://pro.fontawesome.com",
"img-src 'self' data: blob: https://res.cloudinary.com https://avatars.githubusercontent.com https://cdn.shopify.com https://*.myshopify.com https://cdn.jsdelivr.net https://widgets.guidestar.org https://maps.googleapis.com https://maps.gstatic.com https://*.googleapis.com https://images.huffingtonpost.com https://images.ctfassets.net https://www.hackerrank.com https://*.businessinsider.com https://i.insider.com https://cdn.sstatic.net https://i.stack.imgur.com https://stackoverflow.blog https://cdn.stackoverflow.co",
"font-src 'self' data: https://fonts.gstatic.com https://pro.fontawesome.com",
"connect-src 'self' https://www.clarity.ms https://vitals.vercel-insights.com https://github.com https://api.github.com https://hashflagswag.myshopify.com https://res.cloudinary.com https://widgets.guidestar.org https://www.google-analytics.com https://maps.googleapis.com https://cdn.jsdelivr.net https://huggingface.co https://cdn-lfs.huggingface.co https://cdn-lfs-us-1.huggingface.co",
"worker-src 'self' https://cdn.jsdelivr.net",
"frame-src 'self' https://www.youtube.com https://www.youtube-nocookie.com https://donorbox.org",
"media-src 'self' https://res.cloudinary.com",
"object-src 'none'",
"base-uri 'self'",
"form-action 'self'",
"frame-ancestors 'self'",
"upgrade-insecure-requests",
].join("; "),
},
],
},
];
},
// Redirects for old blog pagination URLs
async redirects() {
return [
{
source: "/blogs/blog/page/:page",
destination: "/blogs/blog?page=:page",
permanent: true,
},
];
},
// Optimize file tracing for smaller serverless bundles
outputFileTracingIncludes: {
// Only include specific data files that are needed at runtime
"/": ["src/data/site-config.ts", "src/data/homepages/**/*"],
"/api/**": [], // API routes don't need static data files
"/blogs/blog": ["src/data/blogs/**/*.md"], // Blog listing page needs blog markdown files for SSR
},
// Exclude unnecessary files from serverless functions
outputFileTracingExcludes: {
"/**": [
"node_modules/@playwright/**",
"node_modules/ace-builds/**",
"node_modules/@swc/core-linux-x64-gnu/**",
"node_modules/@swc/core-linux-x64-musl/**",
"node_modules/@swc/core-darwin-x64/**",
"node_modules/@swc/core-win32-x64-msvc/**",
".git/**",
".next/cache/**",
"src/data/curriculum/lessons/**",
"**/*.map",
"**/test/**",
"**/tests/**",
"**/__tests__/**",
"**/*.test.{js,jsx,ts,tsx}",
"**/*.spec.{js,jsx,ts,tsx}",
],
},
webpack(config, { isServer }) {
config.module.rules.push({
test: /\.svg$/,
use: ["@svgr/webpack"],
});
if (!isServer) {
config.resolve.fallback = {
fs: false,
};
}
// Optimize for serverless functions
if (isServer) {
// Enable tree-shaking for server bundles
config.optimization = {
...config.optimization,
// Note: usedExports removed for Next.js 15 compatibility
sideEffects: false,
};
}
return config;
},
images: {
domains: ["res.cloudinary.com", "avatars.githubusercontent.com", "cdn.shopify.com", "hashflagswag.myshopify.com"],
remotePatterns: [
{
protocol: "https",
hostname: "res.cloudinary.com",
},
{
protocol: "https",
hostname: "avatars.githubusercontent.com",
},
{
protocol: "https",
hostname: "cdn.shopify.com",
},
{
protocol: "https",
hostname: "**.myshopify.com",
},
],
unoptimized: false,
},
};
require("dotenv").config();
module.exports = withPWA(nextConfig);