Skip to content

Commit

Permalink
fix: Unable to configure Custom Domain for React-Native
Browse files Browse the repository at this point in the history
  • Loading branch information
sunitaprajapati89 committed Jan 31, 2025
1 parent 6153e20 commit cdf588a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 16 deletions.
28 changes: 16 additions & 12 deletions packages/core/src/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ import {
UserInfoState,
UserTraits,
} from './types';
import { allSettled, getPluginsWithFlush, getPluginsWithReset } from './util';
import {
allSettled,
getPluginsWithFlush,
getPluginsWithReset,
getURL,
} from './util';
import { getUUID } from './uuid';
import type { FlushPolicy } from './flushPolicies';
import {
Expand Down Expand Up @@ -160,15 +165,13 @@ export class SegmentClient {
if (ofType !== undefined) {
return [...(plugins[ofType] ?? [])];
}
return (
[
...this.getPlugins(PluginType.before),
...this.getPlugins(PluginType.enrichment),
...this.getPlugins(PluginType.utility),
...this.getPlugins(PluginType.destination),
...this.getPlugins(PluginType.after),
]
);
return [
...this.getPlugins(PluginType.before),
...this.getPlugins(PluginType.enrichment),
...this.getPlugins(PluginType.utility),
...this.getPlugins(PluginType.destination),
...this.getPlugins(PluginType.after),
];
}

/**
Expand Down Expand Up @@ -320,10 +323,11 @@ export class SegmentClient {

async fetchSettings() {
const settingsPrefix: string = this.config.cdnProxy ?? settingsCDN;
const settingsEndpoint = `${settingsPrefix}/${this.config.writeKey}/settings`;
const settingsEndpoint = `/projects/${this.config.writeKey}/settings`;
const settingsURL = getURL(settingsPrefix, settingsEndpoint);

try {
const res = await fetch(settingsEndpoint, {
const res = await fetch(settingsURL, {
headers: {
'Cache-Control': 'no-cache',
},
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Config } from './types';

export const defaultApiHost = 'https://api.segment.io/v1/b';
export const defaultApiHost = 'api.segment.io/v1';

export const settingsCDN = 'https://cdn-settings.segment.com/v1/projects';
export const settingsCDN = 'cdn-settings.segment.com/v1';

export const defaultConfig: Config = {
writeKey: '',
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/plugins/SegmentDestination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
SegmentEvent,
UpdateType,
} from '../types';
import { chunk, createPromise } from '../util';
import { chunk, createPromise, getURL } from '../util';
import { uploadEvents } from '../api';
import type { SegmentClient } from '../analytics';
import { DestinationMetadataEnrichment } from './DestinationMetadataEnrichment';
Expand Down Expand Up @@ -90,7 +90,7 @@ export class SegmentDestination extends DestinationPlugin {

private getEndpoint(): string {
const config = this.analytics?.getConfig();
return config?.proxy ?? this.apiHost ?? defaultApiHost;
return getURL(config?.proxy ?? this.apiHost ?? defaultApiHost, '/b');
}

configure(analytics: SegmentClient): void {
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,8 @@ export const createPromise = <T>(
resolve: resolver!,
};
};

export function getURL(host: string, path: string) {
const s = `https://${host}${path}`;
return s;
}

0 comments on commit cdf588a

Please sign in to comment.