Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tall-stingrays-approve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@segment/analytics-next': patch
---

Refactor get cdn to have smaller footprint
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import jsdom, { JSDOM } from 'jsdom'
import { InitOptions } from '../../'
import { AnalyticsBrowser, loadLegacySettings } from '../../browser'
import { AnalyticsBrowser } from '../../browser'
import { snippet } from '../../tester/__fixtures__/segment-snippet'
import { install, AnalyticsStandalone } from '../standalone-analytics'
import unfetch from 'unfetch'
Expand Down Expand Up @@ -127,7 +127,7 @@ describe('standalone bundle', () => {
// @ts-ignore ignore Response required fields
.mockImplementation((): Promise<Response> => fetchSettings)

await loadLegacySettings(segmentDotCom)
await install()

expect(unfetch).toHaveBeenCalledWith(
'https://cdn.foo.com/v1/projects/foo/settings'
Expand All @@ -142,7 +142,7 @@ describe('standalone bundle', () => {
const mockCdn = 'http://my-overridden-cdn.com'

window.analytics._cdn = mockCdn
await loadLegacySettings(segmentDotCom)
await install()

expect(unfetch).toHaveBeenCalledWith(expect.stringContaining(mockCdn))
})
Expand Down
8 changes: 3 additions & 5 deletions packages/browser/src/browser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,9 @@ export interface AnalyticsBrowserSettings extends AnalyticsSettings {

export function loadLegacySettings(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this a breaking change. I have seen some users actually use this function in their own code.

writeKey: string,
cdnURL?: string
cdnURL: string
): Promise<LegacySettings> {
const baseUrl = cdnURL ?? getCDN()

return fetch(`${baseUrl}/v1/projects/${writeKey}/settings`)
return fetch(`${cdnURL}/v1/projects/${writeKey}/settings`)
.then((res) => {
if (!res.ok) {
return res.text().then((errorResponseMessage) => {
Expand Down Expand Up @@ -263,7 +261,7 @@ async function loadAnalytics(

const legacySettings =
settings.cdnSettings ??
(await loadLegacySettings(settings.writeKey, settings.cdnURL))
(await loadLegacySettings(settings.writeKey, settings.cdnURL || getCDN()))

const retryQueue: boolean =
legacySettings.integrations['Segment.io']?.retryQueue ?? true
Expand Down