Skip to content

Commit

Permalink
🎨 [RUM] Refactor isIntakeRequest()
Browse files Browse the repository at this point in the history
  • Loading branch information
webNeat committed Nov 16, 2020
1 parent 9123e4b commit 4301386
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions packages/core/src/domain/configuration.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BuildEnv, BuildMode, Datacenter, INTAKE_SITE, STAGING_INTAKE_SITE } from '../boot/init'
import { CookieOptions, getCurrentSite } from '../browser/cookie'
import { getPathName, haveSameOrigin } from '../tools/urlPolyfill'
import { getOrigin, getPathName, haveSameOrigin } from '../tools/urlPolyfill'
import { includes, ONE_KILO_BYTE, ONE_SECOND } from '../tools/utils'

export const DEFAULT_CONFIGURATION = {
Expand Down Expand Up @@ -236,17 +236,25 @@ function getHost(type: EndpointType, conf: TransportConfiguration) {
}

export function isIntakeRequest(url: string, configuration: Configuration) {
return (
getPathName(url).indexOf('/v1/input/') !== -1 &&
(haveSameOrigin(url, configuration.logsEndpoint) ||
haveSameOrigin(url, configuration.rumEndpoint) ||
haveSameOrigin(url, configuration.traceEndpoint) ||
(!!configuration.internalMonitoringEndpoint && haveSameOrigin(url, configuration.internalMonitoringEndpoint)) ||
(!!configuration.replica &&
(haveSameOrigin(url, configuration.replica.logsEndpoint) ||
haveSameOrigin(url, configuration.replica.rumEndpoint) ||
haveSameOrigin(url, configuration.replica.internalMonitoringEndpoint))))
)
if (!getPathName(url).includes('/v1/input/')) return false
return getIntakeEndpoints(configuration)
.map(getOrigin)
.includes(getOrigin(url))
}

function getIntakeEndpoints(configuration: Configuration) {
const endpoints = [configuration.logsEndpoint, configuration.rumEndpoint, configuration.traceEndpoint]
if (!!configuration.internalMonitoringEndpoint) {
endpoints.push(configuration.internalMonitoringEndpoint)
}
if (!!configuration.replica) {
endpoints.push(
configuration.replica.logsEndpoint,
configuration.replica.rumEndpoint,
configuration.replica.internalMonitoringEndpoint
)
}
return endpoints
}

function mustUseSecureCookie(userConfiguration: UserConfiguration) {
Expand Down

0 comments on commit 4301386

Please sign in to comment.