analytics-next
analytics-next copied to clipboard
SEGMENT_API_HOST integrations['Segment.io'].apiHost cannot hit current host
To solve 3rd party script issues we want to proxy our own api.segment.io calls
We're ok having it on the same fqdn and routing back w/ nginx/cloudflare/cloudfront/etc.
But it looks like .send() does not give us an opportunity to put in send it as the same originating domain.
would love for SEGMENT_API_HOST/apiHost just take "/v1", "/segment/v1"
const apiHost = settings?.apiHost ?? SEGMENT_API_HOST
const protocol = settings?.protocol ?? 'https'
const remote = `${protocol}://${apiHost}`
....
return client
.dispatch(
`${remote}/${path}`,
normalize(analytics, json, settings, integrations)
)
.then(() => ctx)
just a note cdnURL will take in '' and '/segment' as prefixes to the current fqdn
export function loadLegacySettings(
writeKey: string,
cdnURL?: string
): Promise<LegacySettings> {
const baseUrl = cdnURL ?? getCDN()
return fetch(`${baseUrl}/v1/projects/${writeKey}/settings`)