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',
'puppeteer',
'require-in-the-middle',
'import-in-the-middle' // Sentry 10+ instrumentation dependencies
'import-in-the-middle'
],
transpilePackages: [
'@mintel/content-engine',
@@ -37,43 +37,6 @@ const nextConfig = {
},
],
},
async rewrites() {
return {
beforeFiles: [
// Assets requested from root
{
source: '/assets/:path*',
destination: '/showcase/klz-cables.com/assets/:path*',
},
{
source: '/wp-content/:path*',
destination: '/showcase/klz-cables.com/assets/klz-cables.com/wp-content/:path*',
},
{
source: '/wp-includes/:path*',
destination: '/showcase/klz-cables.com/assets/klz-cables.com/wp-includes/:path*',
},
// Assets requested relatively from case-studies/work/blog subpages
{
source: '/:folder(case-studies|work|blog)/assets/:path*',
destination: '/showcase/klz-cables.com/assets/:path*',
},
{
source: '/:folder(case-studies|work|blog)/wp-content/:path*',
destination: '/showcase/klz-cables.com/assets/klz-cables.com/wp-content/:path*',
},
{
source: '/:folder(case-studies|work|blog)/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 [
{
@@ -86,7 +49,58 @@ const nextConfig = {
outputFileTracingRoot: path.join(dirname, '../../'),
};
const withMDX = createMDX({
// Add markdown plugins here, as desired
});
export default withPayload(withMintelConfig(withMDX(nextConfig)));
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 {
...normalized,
beforeFiles: [
...(normalized.beforeFiles || []),
// Diagnostic rule
{
source: '/robots-test',
destination: '/robots.txt',
},
// Assets requested from root
{
source: '/assets/:path*',
destination: '/showcase/klz-cables.com/assets/:path*',
},
{
source: '/wp-content/:path*',
destination: '/showcase/klz-cables.com/assets/klz-cables.com/wp-content/:path*',
},
{
source: '/wp-includes/:path*',
destination: '/showcase/klz-cables.com/assets/klz-cables.com/wp-includes/:path*',
},
// Assets requested relatively from case-studies/work/blog subpages
{
source: '/:folder(case-studies|work|blog)/assets/:path*',
destination: '/showcase/klz-cables.com/assets/:path*',
},
{
source: '/:folder(case-studies|work|blog)/wp-content/:path*',
destination: '/showcase/klz-cables.com/assets/klz-cables.com/wp-content/:path*',
},
{
source: '/:folder(case-studies|work|blog)/wp-includes/:path*',
destination: '/showcase/klz-cables.com/assets/klz-cables.com/wp-includes/:path*',
},
],
};
};
export default wrappedConfig;