refactor: clean up apiBaseUrl handling in config merging
This commit is contained in:
@@ -17,7 +17,7 @@ export type ImRealtimeEnvelope = {
|
|||||||
|
|
||||||
export function createImRealtimeConnection() {
|
export function createImRealtimeConnection() {
|
||||||
const config = readKefuWidgetConfig()
|
const config = readKefuWidgetConfig()
|
||||||
const apiBaseUrl = (config.apiBaseUrl || config.baseUrl || "").trim()
|
const apiBaseUrl = (config.apiBaseUrl || "").trim()
|
||||||
const baseUrl = apiBaseUrl
|
const baseUrl = apiBaseUrl
|
||||||
? apiBaseUrl.replace(/^http/, "ws").replace(/\/$/, "")
|
? apiBaseUrl.replace(/^http/, "ws").replace(/\/$/, "")
|
||||||
: createWebSocketBaseUrl()
|
: createWebSocketBaseUrl()
|
||||||
|
|||||||
@@ -41,7 +41,11 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
merged.baseUrl = String(merged.baseUrl || window.location.origin).replace(/\/$/, "");
|
merged.baseUrl = String(merged.baseUrl || window.location.origin).replace(/\/$/, "");
|
||||||
merged.apiBaseUrl = String(merged.apiBaseUrl || merged.baseUrl).replace(/\/$/, "");
|
if (merged.apiBaseUrl) {
|
||||||
|
merged.apiBaseUrl = String(merged.apiBaseUrl).replace(/\/$/, "");
|
||||||
|
} else {
|
||||||
|
delete merged.apiBaseUrl;
|
||||||
|
}
|
||||||
merged.channelId = String(merged.channelId || "");
|
merged.channelId = String(merged.channelId || "");
|
||||||
merged.externalSource = String(merged.externalSource || "web_chat");
|
merged.externalSource = String(merged.externalSource || "web_chat");
|
||||||
return merged;
|
return merged;
|
||||||
@@ -365,9 +369,6 @@
|
|||||||
if (!rawConfig.baseUrl) {
|
if (!rawConfig.baseUrl) {
|
||||||
state.config.baseUrl = widgetBaseUrl;
|
state.config.baseUrl = widgetBaseUrl;
|
||||||
}
|
}
|
||||||
if (!rawConfig.apiBaseUrl) {
|
|
||||||
state.config.apiBaseUrl = state.config.baseUrl;
|
|
||||||
}
|
|
||||||
if (!state.config.channelId) {
|
if (!state.config.channelId) {
|
||||||
console.error("[cs-agent-widget] channelId is required");
|
console.error("[cs-agent-widget] channelId is required");
|
||||||
return;
|
return;
|
||||||
|
|||||||
+5
-4
@@ -41,7 +41,11 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
merged.baseUrl = String(merged.baseUrl || window.location.origin).replace(/\/$/, "");
|
merged.baseUrl = String(merged.baseUrl || window.location.origin).replace(/\/$/, "");
|
||||||
merged.apiBaseUrl = String(merged.apiBaseUrl || merged.baseUrl).replace(/\/$/, "");
|
if (merged.apiBaseUrl) {
|
||||||
|
merged.apiBaseUrl = String(merged.apiBaseUrl).replace(/\/$/, "");
|
||||||
|
} else {
|
||||||
|
delete merged.apiBaseUrl;
|
||||||
|
}
|
||||||
merged.channelId = String(merged.channelId || "");
|
merged.channelId = String(merged.channelId || "");
|
||||||
merged.externalSource = String(merged.externalSource || "web_chat");
|
merged.externalSource = String(merged.externalSource || "web_chat");
|
||||||
return merged;
|
return merged;
|
||||||
@@ -365,9 +369,6 @@
|
|||||||
if (!rawConfig.baseUrl) {
|
if (!rawConfig.baseUrl) {
|
||||||
state.config.baseUrl = widgetBaseUrl;
|
state.config.baseUrl = widgetBaseUrl;
|
||||||
}
|
}
|
||||||
if (!rawConfig.apiBaseUrl) {
|
|
||||||
state.config.apiBaseUrl = state.config.baseUrl;
|
|
||||||
}
|
|
||||||
if (!state.config.channelId) {
|
if (!state.config.channelId) {
|
||||||
console.error("[cs-agent-widget] channelId is required");
|
console.error("[cs-agent-widget] channelId is required");
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user