Skip to content

Commit df749f7

Browse files
authored
Remove signals hostname restriction (#1139)
1 parent 4f283c3 commit df749f7

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

packages/signals/signals/src/core/signal-generators/__tests__/network.test.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,23 @@ describe(matchHostname, () => {
4848
setLocation({ hostname: 'api.example.com' })
4949
expect(matchHostname('https://api.example.com/foo')).toBe(true)
5050
expect(matchHostname('https://foo.com/foo')).toBe(false)
51-
expect(matchHostname('https://example.com/foo')).toBe(false)
51+
expect(matchHostname('https://example.com/foo')).toBe(true)
5252
})
5353

5454
it('should always allow relative domains', () => {
5555
expect(matchHostname('/foo/bar')).toBe(true)
5656
expect(matchHostname('foo/bar')).toBe(true)
5757
expect(matchHostname('foo')).toBe(true)
5858
})
59+
60+
it('should handle www differences', () => {
61+
setLocation({ hostname: 'foo.previews.console.stage.twilio.com' })
62+
expect(
63+
matchHostname(
64+
'https://www.stage.twilio.com/console/billing/api/v3/add-funds'
65+
)
66+
).toBe(true)
67+
})
5968
})
6069

6170
describe(addFetchInterceptor, () => {

packages/signals/signals/src/core/signal-generators/network-gen.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ export const matchHostname = (url: string): boolean => {
3333
// Relative URL will go to this host
3434
return true
3535
}
36-
return new URL(url).hostname.includes(window.location.hostname)
36+
37+
const clean = new URL(url).hostname.replace('www.', '')
38+
const current = window.location.hostname.replace('www.', '')
39+
return clean.includes(current) || current.includes(clean)
3740
}
3841

3942
const normalizeHeaders = (headers: HeadersInit): Headers => {

packages/signals/signals/webpack.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ module.exports = merge(common, {
1414
type: 'umd',
1515
},
1616
},
17+
'analytics-signals.global': {
18+
import: path.resolve(__dirname, 'src/index.ts'),
19+
library: {
20+
type: 'window',
21+
},
22+
},
1723
},
1824
output: {
1925
filename: isProd ? '[name].js' : '[name].development.js',

0 commit comments

Comments
 (0)