Skip to content

Commit 515d808

Browse files
fix: handled the case of appending '/b'
1 parent e154281 commit 515d808

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

packages/core/src/plugins/SegmentDestination.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,26 @@ export class SegmentDestination extends DestinationPlugin {
9292
const config = this.analytics?.getConfig();
9393
const hasProxy = !!(config?.proxy ?? '');
9494
const useSegmentEndpoints = Boolean(config?.useSegmentEndpoints);
95+
// Determine the base URL based on config or this.apiHost, defaulting to defaultApiHost
96+
let baseURL = config?.proxy ?? this.apiHost ?? defaultApiHost;
97+
98+
// If baseURL is null or undefined, fallback to defaultApiHost
99+
if (!baseURL) {
100+
baseURL = defaultApiHost;
101+
}
95102

96103
let endpoint = '';
97104

98105
if (hasProxy) {
99106
endpoint = useSegmentEndpoints ? '/b' : '';
100107
} else {
101-
endpoint = '/b'; // If no proxy, always append '/b'
108+
endpoint = baseURL === defaultApiHost ? '' : '/b';
102109
}
103110

104-
const baseURL = config?.proxy ?? this.apiHost ?? defaultApiHost;
111+
console.log('proxy', config?.proxy);
112+
console.log('apihost', this.apiHost);
113+
console.log('dafault api host', defaultApiHost);
114+
105115
return getURL(baseURL, endpoint);
106116
}
107117
configure(analytics: SegmentClient): void {

packages/core/src/plugins/__tests__/SegmentDestination.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,14 +320,14 @@ describe('SegmentDestination', () => {
320320

321321
expect(sendEventsSpy).toHaveBeenCalledTimes(2);
322322
expect(sendEventsSpy).toHaveBeenCalledWith({
323-
url: getURL(defaultApiHost, '/b'),
323+
url: getURL(defaultApiHost, ''), // default api already appended with '/b'
324324
writeKey: '123-456',
325325
events: events.slice(0, 2).map((e) => ({
326326
...e,
327327
})),
328328
});
329329
expect(sendEventsSpy).toHaveBeenCalledWith({
330-
url: getURL(defaultApiHost, '/b'),
330+
url: getURL(defaultApiHost, ''), // default api already appended with '/b'
331331
writeKey: '123-456',
332332
events: events.slice(2, 4).map((e) => ({
333333
...e,

0 commit comments

Comments
 (0)