Skip to content

Commit

Permalink
🐛 fix issue when using proxy (#530)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcaudan authored Sep 11, 2020
1 parent b4f0fa2 commit 33d0d5e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
5 changes: 2 additions & 3 deletions packages/core/src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,8 @@ export function isIntakeRequest(url: string, configuration: Configuration) {
haveSameOrigin(url, configuration.logsEndpoint) ||
haveSameOrigin(url, configuration.rumEndpoint) ||
haveSameOrigin(url, configuration.traceEndpoint) ||
(configuration.internalMonitoringEndpoint && haveSameOrigin(url, configuration.internalMonitoringEndpoint)) ||
(configuration.proxyHost && haveSameOrigin(url, configuration.proxyHost)) ||
(configuration.replica &&
(!!configuration.internalMonitoringEndpoint && haveSameOrigin(url, configuration.internalMonitoringEndpoint)) ||
(!!configuration.replica &&
(haveSameOrigin(url, configuration.replica.logsEndpoint) ||
haveSameOrigin(url, configuration.replica.rumEndpoint) ||
haveSameOrigin(url, configuration.replica.internalMonitoringEndpoint)))
Expand Down
34 changes: 33 additions & 1 deletion packages/core/test/configuration.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BuildEnv, BuildMode, Datacenter } from '../src'
import { BuildEnv, BuildMode, Datacenter, isIntakeRequest } from '../src'
import { buildConfiguration } from '../src/configuration'

describe('configuration', () => {
Expand Down Expand Up @@ -130,4 +130,36 @@ describe('configuration', () => {
expect(configuration.cookieOptions).toEqual({ secure: false, crossSite: false, domain: jasmine.any(String) })
})
})

describe('isIntakeRequest', () => {
it('should not detect non intake request', () => {
const configuration = buildConfiguration({ clientToken }, usEnv)
expect(isIntakeRequest('https://www.foo.com', configuration)).toBe(false)
})

it('should detect intake request', () => {
const configuration = buildConfiguration({ clientToken }, usEnv)
expect(isIntakeRequest('https://rum-http-intake.logs.datadoghq.com', configuration)).toBe(true)
expect(isIntakeRequest('https://browser-http-intake.logs.datadoghq.com', configuration)).toBe(true)
expect(isIntakeRequest('https://public-trace-http-intake.logs.datadoghq.com', configuration)).toBe(true)
})

it('should detect proxy intake request', () => {
const configuration = buildConfiguration({ clientToken, proxyHost: 'www.proxy.com' }, usEnv)
expect(isIntakeRequest('https://www.proxy.com', configuration)).toBe(true)
})

it('should detect replica intake request', () => {
const configuration = buildConfiguration(
{ clientToken, site: 'foo.com', replica: { clientToken } },
{ ...usEnv, buildMode: BuildMode.STAGING }
)
expect(isIntakeRequest('https://rum-http-intake.logs.foo.com', configuration)).toBe(true)
expect(isIntakeRequest('https://browser-http-intake.logs.foo.com', configuration)).toBe(true)
expect(isIntakeRequest('https://public-trace-http-intake.logs.foo.com', configuration)).toBe(true)

expect(isIntakeRequest('https://rum-http-intake.logs.datadoghq.com', configuration)).toBe(true)
expect(isIntakeRequest('https://browser-http-intake.logs.datadoghq.com', configuration)).toBe(true)
})
})
})

0 comments on commit 33d0d5e

Please sign in to comment.