mirror of
https://github.com/lobehub/lobe-chat.git
synced 2026-06-14 03:30:19 +00:00
🐛 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:
+17
-1
@@ -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;
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user