Skip to content

Commit

Permalink
Remove signals hostname restriction (#1139)
Browse files Browse the repository at this point in the history
  • Loading branch information
silesky authored Sep 6, 2024
1 parent 4f283c3 commit df749f7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,23 @@ describe(matchHostname, () => {
setLocation({ hostname: 'api.example.com' })
expect(matchHostname('https://api.example.com/foo')).toBe(true)
expect(matchHostname('https://foo.com/foo')).toBe(false)
expect(matchHostname('https://example.com/foo')).toBe(false)
expect(matchHostname('https://example.com/foo')).toBe(true)
})

it('should always allow relative domains', () => {
expect(matchHostname('/foo/bar')).toBe(true)
expect(matchHostname('foo/bar')).toBe(true)
expect(matchHostname('foo')).toBe(true)
})

it('should handle www differences', () => {
setLocation({ hostname: 'foo.previews.console.stage.twilio.com' })
expect(
matchHostname(
'https://www.stage.twilio.com/console/billing/api/v3/add-funds'
)
).toBe(true)
})
})

describe(addFetchInterceptor, () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ export const matchHostname = (url: string): boolean => {
// Relative URL will go to this host
return true
}
return new URL(url).hostname.includes(window.location.hostname)

const clean = new URL(url).hostname.replace('www.', '')
const current = window.location.hostname.replace('www.', '')
return clean.includes(current) || current.includes(clean)
}

const normalizeHeaders = (headers: HeadersInit): Headers => {
Expand Down
6 changes: 6 additions & 0 deletions packages/signals/signals/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ module.exports = merge(common, {
type: 'umd',
},
},
'analytics-signals.global': {
import: path.resolve(__dirname, 'src/index.ts'),
library: {
type: 'window',
},
},
},
output: {
filename: isProd ? '[name].js' : '[name].development.js',
Expand Down

0 comments on commit df749f7

Please sign in to comment.