🐛 fix: fix the Worker URL cross-origin issue (#9624)

When the origin of the Worker script is different from the current page, reconstruct the URL relative to the current origin to avoid cross-origin errors.
This commit is contained in:
peerless-hero
2025-10-14 10:16:33 +08:00
committed by GitHub
parent c1a0868ac3
commit d379112d74
+17 -1
View File
@@ -19,9 +19,11 @@ const standaloneConfig: NextConfig = {
outputFileTracingIncludes: { '*': ['public/**/*', '.next/static/**/*'] },
};
const assetPrefix = process.env.NEXT_PUBLIC_ASSET_PREFIX;
const nextConfig: NextConfig = {
...(isStandaloneMode ? standaloneConfig : {}),
assetPrefix: process.env.NEXT_PUBLIC_ASSET_PREFIX,
assetPrefix,
compiler: {
emotion: true,
},
@@ -309,6 +311,20 @@ const nextConfig: NextConfig = {
zipfile: false,
};
if (assetPrefix && (assetPrefix.startsWith('http://') || assetPrefix.startsWith('https://'))) {
// fix the Worker URL cross-origin issue
// refs: https://github.com/lobehub/lobe-chat/pull/9624
config.module.rules.push({
generator: {
// @see https://webpack.js.org/configuration/module/#rulegeneratorpublicpath
publicPath: '/_next/',
},
test: /worker\.ts$/,
// @see https://webpack.js.org/guides/asset-modules/
type: 'asset/resource',
});
}
return config;
},
};