fix: harden next.config rewrites against wrapper overwrites
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 8s
Build & Deploy / 🏗️ Build (push) Successful in 15m9s
Build & Deploy / 🚀 Deploy (push) Successful in 21s
Build & Deploy / 🩺 Smoke Test (push) Failing after 3s
Build & Deploy / 🔔 Notify (push) Successful in 3s

This commit is contained in:
2026-04-12 22:38:46 +02:00
parent c505050cb4
commit 0a9cb81841

View File

@@ -14,7 +14,7 @@ const nextConfig = {
'sharp', 'sharp',
'puppeteer', 'puppeteer',
'require-in-the-middle', 'require-in-the-middle',
'import-in-the-middle' // Sentry 10+ instrumentation dependencies 'import-in-the-middle'
], ],
transpilePackages: [ transpilePackages: [
'@mintel/content-engine', '@mintel/content-engine',
@@ -37,9 +37,42 @@ const nextConfig = {
}, },
], ],
}, },
async rewrites() { async redirects() {
return [
{
source: '/case-studies/klz',
destination: '/case-studies/klz-cables',
permanent: true,
},
];
},
outputFileTracingRoot: path.join(dirname, '../../'),
};
const withMDX = createMDX({});
// Apply wrappers
const wrappedConfig = withPayload(withMintelConfig(withMDX(nextConfig)));
// HARDEN REWRITES: Manually merge showcase rules to prevent wrapper overwrites
const originalRewrites = wrappedConfig.rewrites;
wrappedConfig.rewrites = async () => {
const existing = await originalRewrites?.() || [];
// Normalize existing to object pattern (Next.js supports both Array and Object)
const normalized = Array.isArray(existing)
? { afterFiles: existing, beforeFiles: [], fallback: [] }
: existing;
return { return {
...normalized,
beforeFiles: [ beforeFiles: [
...(normalized.beforeFiles || []),
// Diagnostic rule
{
source: '/robots-test',
destination: '/robots.txt',
},
// Assets requested from root // Assets requested from root
{ {
source: '/assets/:path*', source: '/assets/:path*',
@@ -66,27 +99,8 @@ const nextConfig = {
source: '/:folder(case-studies|work|blog)/wp-includes/:path*', source: '/:folder(case-studies|work|blog)/wp-includes/:path*',
destination: '/showcase/klz-cables.com/assets/klz-cables.com/wp-includes/:path*', destination: '/showcase/klz-cables.com/assets/klz-cables.com/wp-includes/:path*',
}, },
// Diagnostic rule
{
source: '/robots-test',
destination: '/robots.txt',
},
], ],
}; };
},
async redirects() {
return [
{
source: '/case-studies/klz',
destination: '/case-studies/klz-cables',
permanent: true,
},
];
},
outputFileTracingRoot: path.join(dirname, '../../'),
}; };
const withMDX = createMDX({ export default wrappedConfig;
// Add markdown plugins here, as desired
});
export default withPayload(withMintelConfig(withMDX(nextConfig)));