fix: ensure rewrites are merged when config is a function (withPayload)
Some checks failed
Some checks failed
This commit is contained in:
@@ -51,56 +51,52 @@ const nextConfig = {
|
|||||||
|
|
||||||
const withMDX = createMDX({});
|
const withMDX = createMDX({});
|
||||||
|
|
||||||
// Apply wrappers
|
// Execute wrappers
|
||||||
const wrappedConfig = withPayload(withMintelConfig(withMDX(nextConfig)));
|
let config = withPayload(withMintelConfig(withMDX(nextConfig)));
|
||||||
|
|
||||||
// HARDEN REWRITES: Manually merge showcase rules to prevent wrapper overwrites
|
/**
|
||||||
const originalRewrites = wrappedConfig.rewrites;
|
* Injects our critical showcase rewrites into a resolved Next.js config object.
|
||||||
wrappedConfig.rewrites = async () => {
|
*/
|
||||||
const existing = await originalRewrites?.() || [];
|
function injectShowcaseRewrites(resolvedConfig) {
|
||||||
|
const originalRewrites = resolvedConfig.rewrites;
|
||||||
|
|
||||||
// Normalize existing to object pattern (Next.js supports both Array and Object)
|
resolvedConfig.rewrites = async () => {
|
||||||
const normalized = Array.isArray(existing)
|
const existing = await originalRewrites?.() || [];
|
||||||
? { afterFiles: existing, beforeFiles: [], fallback: [] }
|
|
||||||
: existing;
|
// Normalize existing to object pattern
|
||||||
|
const normalized = Array.isArray(existing)
|
||||||
|
? { afterFiles: existing, beforeFiles: [], fallback: [] }
|
||||||
|
: existing;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...normalized,
|
...normalized,
|
||||||
beforeFiles: [
|
beforeFiles: [
|
||||||
...(normalized.beforeFiles || []),
|
...(normalized.beforeFiles || []),
|
||||||
// Diagnostic rule
|
// Diagnostic rule
|
||||||
{
|
{ source: '/robots-test', destination: '/robots.txt' },
|
||||||
source: '/robots-test',
|
// Showcase Assets
|
||||||
destination: '/robots.txt',
|
{ 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*' },
|
||||||
// Assets requested from root
|
{ source: '/wp-includes/:path*', destination: '/showcase/klz-cables.com/assets/klz-cables.com/wp-includes/:path*' },
|
||||||
{
|
{ source: '/:folder(case-studies|work|blog)/assets/:path*', destination: '/showcase/klz-cables.com/assets/:path*' },
|
||||||
source: '/assets/:path*',
|
{ source: '/:folder(case-studies|work|blog)/wp-content/:path*', destination: '/showcase/klz-cables.com/assets/klz-cables.com/wp-content/:path*' },
|
||||||
destination: '/showcase/klz-cables.com/assets/:path*',
|
{ source: '/:folder(case-studies|work|blog)/wp-includes/:path*', destination: '/showcase/klz-cables.com/assets/klz-cables.com/wp-includes/: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*',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
};
|
||||||
};
|
|
||||||
|
return resolvedConfig;
|
||||||
|
}
|
||||||
|
|
||||||
export default wrappedConfig;
|
// Handle both standard objects and functional wrappers (like withPayload)
|
||||||
|
if (typeof config === 'function') {
|
||||||
|
const originalConfigWrapper = config;
|
||||||
|
config = async (phase, args) => {
|
||||||
|
const resolved = await originalConfigWrapper(phase, args);
|
||||||
|
return injectShowcaseRewrites(resolved);
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
config = injectShowcaseRewrites(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default config;
|
||||||
|
|||||||
Reference in New Issue
Block a user