Skip to content

Commit 6a66e66

Browse files
committed
Revert "ref(utils): get global url"
This reverts commit 61feeeb.
1 parent b5c9c6e commit 6a66e66

File tree

5 files changed

+27
-29
lines changed

5 files changed

+27
-29
lines changed

packages/core/src/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export function initAPIDetails(dsn: DsnLike, metadata?: SdkMetadata, tunnel?: st
9898
function getBaseApiEndpoint(dsn: Dsn): string {
9999
const protocol = dsn.protocol ? `${dsn.protocol}:` : '';
100100
const port = dsn.port ? `:${dsn.port}` : '';
101-
return `${protocol}//${dsn.hostname}${port}${dsn.path ? `/${dsn.path}` : ''}/api/`;
101+
return `${protocol}//${dsn.host}${port}${dsn.path ? `/${dsn.path}` : ''}/api/`;
102102
}
103103

104104
/** Returns the ingest API endpoint for target. */

packages/node/src/integrations/utils/http.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function isSentryRequest(url: string): boolean {
1414
const dsn = getCurrentHub()
1515
.getClient()
1616
?.getDsn();
17-
return dsn ? url.includes(dsn.hostname) : false;
17+
return dsn ? url.includes(dsn.host) : false;
1818
}
1919

2020
/**

packages/types/src/dsn.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface DsnComponents {
1212
/** Private authorization key (deprecated, optional). */
1313
pass?: string;
1414
/** Hostname of the Sentry instance. */
15-
hostname: string;
15+
host: string;
1616
/** Port of the Sentry instance. */
1717
port?: string;
1818
/** Sub path/ */

packages/utils/src/dsn.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Dsn, DsnComponents, DsnLike, DsnProtocol } from '@sentry/types';
22

33
import { isDebugBuild } from './env';
44
import { SentryError } from './error';
5-
import { getGlobalObject } from './global';
65

76
function isValidProtocol(protocol?: string): protocol is DsnProtocol {
87
return protocol === 'http' || protocol === 'https';
@@ -22,22 +21,21 @@ function normalizeProtocol(input: string): string {
2221
* @param withPassword When set to true, the password will be included.
2322
*/
2423
function dsntoString(dsn: Dsn, withPassword: boolean = false): string {
25-
const { hostname, port, path, pass, projectId, protocol, publicKey } = dsn;
24+
const { host, port, path, pass, projectId, protocol, publicKey } = dsn;
2625
return (
2726
`${protocol}://${publicKey}${withPassword && pass ? `:${pass}` : ''}` +
28-
`@${hostname}${port ? `:${port}` : ''}${path}/${projectId}`
27+
`@${host}${port ? `:${port}` : ''}${path}/${projectId}`
2928
);
3029
}
3130

3231
function dsnFromString(str: string): Dsn {
33-
const global = getGlobalObject<{ URL: typeof URL }>();
34-
const url = new global.URL(str);
32+
const url = new URL(str);
3533

3634
const pathComponents = url.pathname.split('/');
3735
const projectId = pathComponents.pop();
3836

3937
return dsnFromComponents({
40-
hostname: url.hostname,
38+
host: url.hostname,
4139
pass: url.password,
4240
path: pathComponents.join('/'),
4341
projectId: projectId || '',
@@ -58,7 +56,7 @@ function dsnFromComponents(components: DsnComponents): Dsn {
5856
protocol: components.protocol,
5957
publicKey: components.publicKey || '',
6058
pass: components.pass || '',
61-
hostname: components.hostname,
59+
host: components.host,
6260
port: components.port || '',
6361
path: components.path || '',
6462
projectId: components.projectId,
@@ -69,7 +67,7 @@ function validateDsn(dsn: Dsn): boolean {
6967
if (isDebugBuild()) {
7068
const { port, projectId, protocol } = dsn;
7169

72-
const requiredComponents: ReadonlyArray<keyof DsnComponents> = ['protocol', 'publicKey', 'hostname', 'projectId'];
70+
const requiredComponents: ReadonlyArray<keyof DsnComponents> = ['protocol', 'publicKey', 'host', 'projectId'];
7371
requiredComponents.forEach(component => {
7472
if (!dsn[component]) {
7573
throw new SentryError(`Invalid Dsn: ${component} missing`);

packages/utils/test/dsn.test.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe('Dsn', () => {
1111
describe('fromComponents', () => {
1212
test('applies all components', () => {
1313
const dsn = makeDsn({
14-
hostname: 'sentry.io',
14+
host: 'sentry.io',
1515
pass: 'xyz',
1616
port: '1234',
1717
projectId: '123',
@@ -21,23 +21,23 @@ describe('Dsn', () => {
2121
expect(dsn.protocol).toBe('https');
2222
expect(dsn.publicKey).toBe('abc');
2323
expect(dsn.pass).toBe('xyz');
24-
expect(dsn.hostname).toBe('sentry.io');
24+
expect(dsn.host).toBe('sentry.io');
2525
expect(dsn.port).toBe('1234');
2626
expect(dsn.path).toBe('');
2727
expect(dsn.projectId).toBe('123');
2828
});
2929

3030
test('applies partial components', () => {
3131
const dsn = makeDsn({
32-
hostname: 'sentry.io',
32+
host: 'sentry.io',
3333
projectId: '123',
3434
protocol: 'https',
3535
publicKey: 'abc',
3636
});
3737
expect(dsn.protocol).toBe('https');
3838
expect(dsn.publicKey).toBe('abc');
3939
expect(dsn.pass).toBe('');
40-
expect(dsn.hostname).toBe('sentry.io');
40+
expect(dsn.host).toBe('sentry.io');
4141
expect(dsn.port).toBe('');
4242
expect(dsn.path).toBe('');
4343
expect(dsn.projectId).toBe('123');
@@ -46,33 +46,33 @@ describe('Dsn', () => {
4646
testIf(isDebugBuild())('throws for missing components', () => {
4747
expect(() =>
4848
makeDsn({
49-
hostname: '',
49+
host: '',
5050
projectId: '123',
51-
protocol: 'https',
51+
protocol: 'https:',
5252
publicKey: 'abc',
5353
}),
5454
).toThrow(SentryError);
5555
expect(() =>
5656
makeDsn({
57-
hostname: 'sentry.io',
57+
host: 'sentry.io',
5858
projectId: '',
59-
protocol: 'https',
59+
protocol: 'https:',
6060
publicKey: 'abc',
6161
}),
6262
).toThrow(SentryError);
6363
expect(() =>
6464
makeDsn({
65-
hostname: 'sentry.io',
65+
host: 'sentry.io',
6666
projectId: '123',
6767
protocol: '' as 'http', // Trick the type checker here
6868
publicKey: 'abc',
6969
}),
7070
).toThrow(SentryError);
7171
expect(() =>
7272
makeDsn({
73-
hostname: 'sentry.io',
73+
host: 'sentry.io',
7474
projectId: '123',
75-
protocol: 'https',
75+
protocol: 'https:',
7676
publicKey: '',
7777
}),
7878
).toThrow(SentryError);
@@ -81,18 +81,18 @@ describe('Dsn', () => {
8181
testIf(isDebugBuild())('throws for invalid components', () => {
8282
expect(() =>
8383
makeDsn({
84-
hostname: 'sentry.io',
84+
host: 'sentry.io',
8585
projectId: '123',
8686
protocol: 'httpx' as 'http', // Trick the type checker here
8787
publicKey: 'abc',
8888
}),
8989
).toThrow(SentryError);
9090
expect(() =>
9191
makeDsn({
92-
hostname: 'sentry.io',
92+
host: 'sentry.io',
9393
port: 'xxx',
9494
projectId: '123',
95-
protocol: 'https',
95+
protocol: 'https:',
9696
publicKey: 'abc',
9797
}),
9898
).toThrow(SentryError);
@@ -105,7 +105,7 @@ describe('Dsn', () => {
105105
expect(dsn.protocol).toBe('https');
106106
expect(dsn.publicKey).toBe('abc');
107107
expect(dsn.pass).toBe('xyz');
108-
expect(dsn.hostname).toBe('sentry.io');
108+
expect(dsn.host).toBe('sentry.io');
109109
expect(dsn.port).toBe('1234');
110110
expect(dsn.path).toBe('');
111111
expect(dsn.projectId).toBe('123');
@@ -116,7 +116,7 @@ describe('Dsn', () => {
116116
expect(dsn.protocol).toBe('https');
117117
expect(dsn.publicKey).toBe('abc');
118118
expect(dsn.pass).toBe('');
119-
expect(dsn.hostname).toBe('sentry.io');
119+
expect(dsn.host).toBe('sentry.io');
120120
expect(dsn.port).toBe('');
121121
expect(dsn.path).toBe('/123');
122122
expect(dsn.projectId).toBe('321');
@@ -127,7 +127,7 @@ describe('Dsn', () => {
127127
expect(dsn.protocol).toBe('https');
128128
expect(dsn.publicKey).toBe('abc');
129129
expect(dsn.pass).toBe('');
130-
expect(dsn.hostname).toBe('sentry.io');
130+
expect(dsn.host).toBe('sentry.io');
131131
expect(dsn.port).toBe('');
132132
expect(dsn.path).toBe('/sentry/custom/installation');
133133
expect(dsn.projectId).toBe('321');
@@ -138,7 +138,7 @@ describe('Dsn', () => {
138138
expect(dsn.protocol).toBe('https');
139139
expect(dsn.publicKey).toBe('abc');
140140
expect(dsn.pass).toBe('');
141-
expect(dsn.hostname).toBe('sentry.io');
141+
expect(dsn.host).toBe('sentry.io');
142142
expect(dsn.port).toBe('');
143143
expect(dsn.path).toBe('');
144144
expect(dsn.projectId).toBe('321');

0 commit comments

Comments
 (0)