forked from ycode/ycode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnext.config.ts
More file actions
133 lines (123 loc) · 4.28 KB
/
Copy pathnext.config.ts
File metadata and controls
133 lines (123 loc) · 4.28 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
import type { NextConfig } from 'next';
const imageRemotePatterns: NonNullable<NonNullable<NextConfig['images']>['remotePatterns']> = [
{
protocol: 'https',
hostname: '**.supabase.co',
pathname: '/storage/v1/object/public/**',
},
];
// Self-hosted Supabase: allow the custom domain for storage image optimization.
// Supports both "https://supabase.example.com" and bare "supabase.example.com".
if (process.env.SUPABASE_URL) {
try {
const parsed = new URL(
process.env.SUPABASE_URL.startsWith('http')
? process.env.SUPABASE_URL
: `https://${process.env.SUPABASE_URL}`,
);
imageRemotePatterns.push({
protocol: (parsed.protocol.replace(':', '') as 'http' | 'https') || 'https',
hostname: parsed.hostname,
pathname: '/storage/v1/object/public/**',
});
} catch {
// Invalid SUPABASE_URL — skip adding remote pattern
}
}
const nextConfig: NextConfig = {
trailingSlash: false,
staticPageGenerationTimeout: 120,
experimental: {
proxyClientMaxBodySize: '500mb',
},
images: {
remotePatterns: imageRemotePatterns,
},
// Ensure sharp works properly in serverless environments (Vercel)
// Also externalize Knex database drivers (we only use PostgreSQL)
// This works for both webpack and Turbopack
serverExternalPackages: [
'sharp',
'oracledb',
'mysql',
'mysql2',
'sqlite3',
'better-sqlite3',
'tedious',
'pg-query-stream',
],
// Turbopack configuration
// Map unused database drivers to stub modules (we only use PostgreSQL)
// This prevents Turbopack from trying to resolve packages that aren't installed
turbopack: {
resolveAlias: {
// Map unused database drivers to stub module to prevent resolution errors
'oracledb': './lib/stubs/db-driver-stub.ts',
'mysql': './lib/stubs/db-driver-stub.ts',
'mysql2': './lib/stubs/db-driver-stub.ts',
'sqlite3': './lib/stubs/db-driver-stub.ts',
'better-sqlite3': './lib/stubs/db-driver-stub.ts',
'tedious': './lib/stubs/db-driver-stub.ts',
'pg-query-stream': './lib/stubs/db-driver-stub.ts',
},
},
async headers() {
return [
{
// Asset proxy: immutable caching (content-addressed by hash)
source: '/a/:path*',
headers: [
{
key: 'Cache-Control',
value: 'public, max-age=31536000, immutable',
},
],
},
{
// Apply to public pages ONLY (exclude /ycode/*, /_next/*, /a/*)
// NOTE: Do NOT set Cache-Control here. Vercel recommends letting
// ISR manage cache headers automatically so per-URL cache-tag
// tracking works for selective revalidateTag invalidations.
// Manual s-maxage breaks per-URL purging on catch-all routes.
source: '/:path((?!ycode|_next|a/).*)*',
headers: [
{
// Open the TLS connection to fonts.gstatic.com while the document
// is still streaming so woff2 binaries can be fetched the moment
// the inlined @font-face rules are parsed. Sending this as a
// response header (vs. <link rel=preconnect> in <head>) lets the
// browser act on it before parsing the document.
key: 'Link',
value: '<https://fonts.gstatic.com>; rel=preconnect; crossorigin',
},
],
},
];
},
webpack: (config, { isServer }) => {
if (isServer) {
// Ignore optional dependencies that Knex tries to load
// We only use PostgreSQL, so we don't need these drivers
config.externals = config.externals || [];
config.externals.push({
'oracledb': 'commonjs oracledb',
'mysql': 'commonjs mysql',
'mysql2': 'commonjs mysql2',
'sqlite3': 'commonjs sqlite3',
'better-sqlite3': 'commonjs better-sqlite3',
'tedious': 'commonjs tedious',
'pg-query-stream': 'commonjs pg-query-stream',
});
}
// Suppress Knex migration warnings (we don't use migrations in Next.js runtime)
config.ignoreWarnings = [
...(config.ignoreWarnings || []),
{
module: /node_modules\/knex\/lib\/migrations\/util\/import-file\.js/,
message: /Critical dependency: the request of a dependency is an expression/,
},
];
return config;
},
};
export default nextConfig;