fix: harden next.config rewrites against wrapper overwrites
Some checks failed
Some checks failed
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user