-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnext.config.ts
More file actions
212 lines (204 loc) · 7.04 KB
/
next.config.ts
File metadata and controls
212 lines (204 loc) · 7.04 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
203
204
205
206
207
208
209
210
211
212
import withBundleAnalyzer from "@next/bundle-analyzer";
import type { NextConfig } from "next";
const isProduction = process.env.NODE_ENV === "production";
const baselineSecurityHeaders = [
{ key: "Permissions-Policy", value: "camera=(), geolocation=(), microphone=()" },
{ key: "Referrer-Policy", value: "strict-origin-when-cross-origin" },
{ key: "X-Content-Type-Options", value: "nosniff" },
{ key: "X-Frame-Options", value: "DENY" },
...(isProduction
? [
{
key: "Strict-Transport-Security",
value: "max-age=63072000; includeSubDomains; preload",
},
]
: []),
] satisfies Array<{ key: string; value: string }>;
const sensitiveNoStoreHeaders = [
{ key: "Cache-Control", value: "private, no-store, max-age=0" },
{ key: "Referrer-Policy", value: "no-referrer" },
{ key: "X-Robots-Tag", value: "noindex, nofollow, noarchive" },
] satisfies Array<{ key: string; value: string }>;
// Authenticated app shell (dashboard, businesses hub, business-scoped pages).
// These URLs are user-private but do NOT carry tokens in the path, so we allow
// the Next.js router cache to prefetch RSC payloads. `private, max-age=0`
// keeps shared caches (CDNs, proxies) out while letting the browser / router
// cache serve instant navigations. Without this relaxation the router cannot
// honor `experimental.staleTimes` and every navigation re-fetches from origin.
const authenticatedAppShellHeaders = [
{ key: "Cache-Control", value: "private, max-age=0, must-revalidate" },
{ key: "Referrer-Policy", value: "no-referrer" },
{ key: "X-Robots-Tag", value: "noindex, nofollow, noarchive" },
] satisfies Array<{ key: string; value: string }>;
const apiNoIndexHeaders = [
{ key: "Cache-Control", value: "private, no-store, max-age=0" },
{ key: "X-Robots-Tag", value: "noindex, nofollow, noarchive" },
] satisfies Array<{ key: string; value: string }>;
const agentDiscoveryHeaders = [
{
key: "Link",
value:
'</.well-known/api-catalog>; rel="api-catalog", </.well-known/agent-skills/index.json>; rel="agent-skills", </.well-known/mcp/server-card.json>; rel="mcp-server-card"',
},
] satisfies Array<{ key: string; value: string }>;
const nextConfig: NextConfig = {
// Skip type-checking during `next build` — types are validated separately
// via `npm run check`. Works around a Next.js 16 Turbopack bug where the
// auto-generated route validator truncates paths containing parenthesized
// route groups (e.g. `(public)/b/[slug]/page`).
typescript: {
ignoreBuildErrors: true,
},
// Ensure preview bots get full metadata in the initial HTML (see Next.js streaming metadata).
htmlLimitedBots:
/facebookexternalhit|Facebot|LinkedInBot|Twitterbot|Pinterest|Slackbot|Discordbot|vkShare|redditbot|Applebot|WhatsApp|TelegramBot|Googlebot|bingbot|Embedly|ChatGPT-User|GPTBot|OAI-SearchBot|anthropic-ai|ClaudeBot|Claude-Web|PerplexityBot|Bytespider|CCBot/i,
cacheComponents: true,
// Populate entries here only when `ANALYZE=true npm run build` shows a measurable
// bundle-size win for a specific package. Keep the block present and documented so
// future wins (e.g., barrel-heavy icon libraries) have a clear home.
// NOTE: lucide-react uses dual export names (e.g. ChevronDown + ChevronDownIcon)
// which breaks modularizeImports transforms. Tree-shaking handles it fine without.
modularizeImports: {},
images: {
// Only add hosts here when a new <Image src="https://..."> is introduced.
// All current images are local or generated via next/image routes.
remotePatterns: [],
},
experimental: {
instantNavigationDevToolsToggle: true,
serverActions: {
bodySizeLimit: "7mb",
},
// Router cache freshness-vs-reuse (ref: bundled staleTimes.md, prefetching.md).
// dynamic: RSC payloads gated on per-request data (session, business context)
// reuse for a short window so back/forward feels instant without serving
// meaningfully stale business data. 30s keeps sibling navs snappy while
// ensuring mutations surface within half a minute at worst.
// static: Segments with no per-request variance (prefetched static shells)
// tolerate a longer reuse window since their content changes infrequently
// and cache-tag invalidations flush them on mutation anyway. 180s balances
// network savings against reasonable freshness for non-mutated reads.
staleTimes: {
dynamic: 30,
static: 180,
},
inlineCss: true,
},
async redirects() {
return [
{
source: "/dashboard",
destination: "/home",
permanent: true,
},
{
source: "/:businessSlug/dashboard",
destination: "/:businessSlug/home",
permanent: true,
},
];
},
async headers() {
return [
{
source: "/",
headers: agentDiscoveryHeaders,
},
{
source: "/:path*",
headers: baselineSecurityHeaders,
},
{
source: "/api/:path*",
headers: apiNoIndexHeaders,
},
{
source: "/businesses/:path*",
headers: authenticatedAppShellHeaders,
},
{
source: "/account/:path*",
headers: authenticatedAppShellHeaders,
},
{
source: "/admin/:path*",
headers: authenticatedAppShellHeaders,
},
{
source: "/onboarding/:path*",
headers: authenticatedAppShellHeaders,
},
{
source: "/forgot-password",
headers: sensitiveNoStoreHeaders,
},
{
source: "/invite/:path*",
headers: sensitiveNoStoreHeaders,
},
{
source: "/login",
headers: sensitiveNoStoreHeaders,
},
{
source: "/inquire/:path*",
headers: [
{
key: "Cache-Control",
value: "public, s-maxage=60, stale-while-revalidate=300",
},
{ key: "Vary", value: "Accept-Encoding" },
],
},
{
source: "/quote/:path*",
headers: [
{
key: "Cache-Control",
value: "public, s-maxage=60, stale-while-revalidate=300",
},
{ key: "Referrer-Policy", value: "no-referrer" },
{ key: "Vary", value: "Accept-Encoding" },
],
},
{
source: "/b/:path*",
headers: sensitiveNoStoreHeaders,
},
{
source: "/reset-password",
headers: sensitiveNoStoreHeaders,
},
{
source: "/signup",
headers: sensitiveNoStoreHeaders,
},
{
source: "/verify-email",
headers: sensitiveNoStoreHeaders,
},
{
source: "/sw.js",
headers: [
{
key: "Cache-Control",
value: "public, max-age=0, must-revalidate",
},
],
},
{
source: "/:path*.svg",
headers: [
{
key: "Cache-Control",
value: "public, max-age=31536000, immutable",
},
],
},
];
},
};
export default withBundleAnalyzer({ enabled: process.env.ANALYZE === "true" })(
nextConfig,
);