fix: 在 craco.config.js 中将 /bytedesk 代理移出 Mock 模式条件判断
现在 /bytedesk 代理始终启用,指向 https://valuefrontier.cn
This commit is contained in:
@@ -284,9 +284,19 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// 代理配置:将 /api 请求代理到后端服务器
|
// 代理配置:将 /api 请求代理到后端服务器
|
||||||
// 注意:Mock 模式下禁用 proxy,让 MSW 拦截请求
|
// 注意:Mock 模式下禁用 /api 和 /concept-api,让 MSW 拦截请求
|
||||||
...(isMockMode() ? {} : {
|
// 但 /bytedesk 始终启用(客服系统不走 Mock)
|
||||||
proxy: {
|
proxy: {
|
||||||
|
'/bytedesk': {
|
||||||
|
target: 'https://valuefrontier.cn', // 统一使用生产环境 Nginx 代理
|
||||||
|
changeOrigin: true,
|
||||||
|
secure: false, // 开发环境禁用 HTTPS 严格验证
|
||||||
|
logLevel: 'debug',
|
||||||
|
ws: true, // 支持 WebSocket
|
||||||
|
// 不使用 pathRewrite,保留 /bytedesk 前缀,让生产 Nginx 处理
|
||||||
|
},
|
||||||
|
// Mock 模式下禁用其他代理
|
||||||
|
...(isMockMode() ? {} : {
|
||||||
'/api': {
|
'/api': {
|
||||||
target: 'http://49.232.185.254:5001',
|
target: 'http://49.232.185.254:5001',
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
@@ -300,15 +310,7 @@ module.exports = {
|
|||||||
logLevel: 'debug',
|
logLevel: 'debug',
|
||||||
pathRewrite: { '^/concept-api': '' },
|
pathRewrite: { '^/concept-api': '' },
|
||||||
},
|
},
|
||||||
'/bytedesk': {
|
|
||||||
target: 'https://valuefrontier.cn', // 统一使用生产环境 Nginx 代理
|
|
||||||
changeOrigin: true,
|
|
||||||
secure: false, // 开发环境禁用 HTTPS 严格验证
|
|
||||||
logLevel: 'debug',
|
|
||||||
ws: true, // 支持 WebSocket
|
|
||||||
// 不使用 pathRewrite,保留 /bytedesk 前缀,让生产 Nginx 处理
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -78,27 +78,44 @@ const BytedeskWidget = ({
|
|||||||
document.body.appendChild(script);
|
document.body.appendChild(script);
|
||||||
scriptRef.current = script;
|
scriptRef.current = script;
|
||||||
|
|
||||||
// 清理函数
|
// 清理函数 - 增强错误处理,防止 React 18 StrictMode 双重清理报错
|
||||||
return () => {
|
return () => {
|
||||||
console.log('[Bytedesk] 清理Widget');
|
console.log('[Bytedesk] 清理Widget');
|
||||||
|
|
||||||
// 移除脚本
|
// 移除脚本
|
||||||
if (scriptRef.current && document.body.contains(scriptRef.current)) {
|
try {
|
||||||
document.body.removeChild(scriptRef.current);
|
if (scriptRef.current && scriptRef.current.parentNode) {
|
||||||
|
scriptRef.current.parentNode.removeChild(scriptRef.current);
|
||||||
|
}
|
||||||
|
scriptRef.current = null;
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('[Bytedesk] 移除脚本失败(可能已被移除):', error.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 移除Widget DOM元素
|
// 移除Widget DOM元素
|
||||||
|
try {
|
||||||
const widgetElements = document.querySelectorAll('[class*="bytedesk"], [id*="bytedesk"]');
|
const widgetElements = document.querySelectorAll('[class*="bytedesk"], [id*="bytedesk"]');
|
||||||
widgetElements.forEach(el => {
|
widgetElements.forEach(el => {
|
||||||
if (el && el.parentNode) {
|
try {
|
||||||
|
if (el && el.parentNode && el.parentNode.contains(el)) {
|
||||||
el.parentNode.removeChild(el);
|
el.parentNode.removeChild(el);
|
||||||
}
|
}
|
||||||
|
} catch (err) {
|
||||||
|
// 忽略单个元素移除失败(可能已被移除)
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('[Bytedesk] 清理Widget DOM元素失败:', error.message);
|
||||||
|
}
|
||||||
|
|
||||||
// 清理全局对象
|
// 清理全局对象
|
||||||
|
try {
|
||||||
if (window.BytedeskWeb) {
|
if (window.BytedeskWeb) {
|
||||||
delete window.BytedeskWeb;
|
delete window.BytedeskWeb;
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('[Bytedesk] 清理全局对象失败:', error.message);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}, [config, autoLoad, onLoad, onError]);
|
}, [config, autoLoad, onLoad, onError]);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user