-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnext.config.mjs
More file actions
67 lines (63 loc) · 1.78 KB
/
next.config.mjs
File metadata and controls
67 lines (63 loc) · 1.78 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
/** @type {import('next').NextConfig} */
const nextConfig = {
output: process.env.NEXT_OUTPUT || undefined,
// Enable Next.js 16 cache components
cacheComponents: true,
turbopack: {
root: process.cwd().replace('/next', ''),
},
images: {
// Disable image optimization for localhost in development
...(process.env.NODE_ENV === 'development' ? { unoptimized: true } : {}),
remotePatterns: [
{
protocol: 'http',
hostname: 'localhost',
port: '1337',
pathname: '/uploads/**',
},
{
protocol: 'https',
hostname: process.env.IMAGE_HOSTNAME || 'localhost',
pathname: '/uploads/**',
},
{
protocol: 'https',
hostname: '*.strapiapp.com',
},
],
},
pageExtensions: ['ts', 'tsx'],
async redirects() {
if (process.env.NEXT_PUBLIC_API_URL === undefined) {
console.warn(
'[next.config] NEXT_PUBLIC_API_URL is not defined. Skipping redirect generation.'
);
return [];
}
let redirections = [];
try {
const res = await fetch(
`${process.env.NEXT_PUBLIC_API_URL}/api/redirections`
);
const result = await res.json();
const redirectItems = result.data.map(({ source, destination }) => {
return {
source: `/:locale${source}`,
destination: `/:locale${destination}`,
permanent: false,
};
});
redirections = redirections.concat(redirectItems);
return redirections;
} catch (error) {
// Log warning but don't fail build - redirects are optional
console.warn(
'[next.config] Failed to fetch redirects from Strapi:',
error instanceof Error ? error.message : error
);
return [];
}
},
};
export default nextConfig;