@@ -18,21 +18,30 @@ export class API {
1818 /** The internally used Dsn object. */
1919 private readonly _dsnObject : Dsn ;
2020
21+ /** The envelope tunnel to use. */
22+ private readonly _tunnel ?: string ;
23+
2124 /** Create a new instance of API */
22- public constructor ( dsn : DsnLike , metadata : SdkMetadata = { } ) {
25+ public constructor ( dsn : DsnLike , metadata : SdkMetadata = { } , tunnel ?: string ) {
2326 this . dsn = dsn ;
2427 this . _dsnObject = new Dsn ( dsn ) ;
2528 this . metadata = metadata ;
29+ this . _tunnel = tunnel ;
2630 }
2731
2832 /** Returns the Dsn object. */
2933 public getDsn ( ) : Dsn {
3034 return this . _dsnObject ;
3135 }
3236
37+ /** Does this transport force envelopes? */
38+ public forceEnvelope ( ) : boolean {
39+ return ! ! this . _tunnel ;
40+ }
41+
3342 /** Returns the prefix to construct Sentry ingestion API endpoints. */
3443 public getBaseApiEndpoint ( ) : string {
35- const dsn = this . _dsnObject ;
44+ const dsn = this . getDsn ( ) ;
3645 const protocol = dsn . protocol ? `${ dsn . protocol } :` : '' ;
3746 const port = dsn . port ? `:${ dsn . port } ` : '' ;
3847 return `${ protocol } //${ dsn . host } ${ port } ${ dsn . path ? `/${ dsn . path } ` : '' } /api/` ;
@@ -58,12 +67,16 @@ export class API {
5867 * Sending auth as part of the query string and not as custom HTTP headers avoids CORS preflight requests.
5968 */
6069 public getEnvelopeEndpointWithUrlEncodedAuth ( ) : string {
70+ if ( this . forceEnvelope ( ) ) {
71+ return this . _tunnel as string ;
72+ }
73+
6174 return `${ this . _getEnvelopeEndpoint ( ) } ?${ this . _encodedAuth ( ) } ` ;
6275 }
6376
6477 /** Returns only the path component for the store endpoint. */
6578 public getStoreEndpointPath ( ) : string {
66- const dsn = this . _dsnObject ;
79+ const dsn = this . getDsn ( ) ;
6780 return `${ dsn . path ? `/${ dsn . path } ` : '' } /api/${ dsn . projectId } /store/` ;
6881 }
6982
@@ -73,7 +86,7 @@ export class API {
7386 */
7487 public getRequestHeaders ( clientName : string , clientVersion : string ) : { [ key : string ] : string } {
7588 // CHANGE THIS to use metadata but keep clientName and clientVersion compatible
76- const dsn = this . _dsnObject ;
89+ const dsn = this . getDsn ( ) ;
7790 const header = [ `Sentry sentry_version=${ SENTRY_API_VERSION } ` ] ;
7891 header . push ( `sentry_client=${ clientName } /${ clientVersion } ` ) ;
7992 header . push ( `sentry_key=${ dsn . publicKey } ` ) ;
@@ -94,7 +107,7 @@ export class API {
94107 user ?: { name ?: string ; email ?: string } ;
95108 } = { } ,
96109 ) : string {
97- const dsn = this . _dsnObject ;
110+ const dsn = this . getDsn ( ) ;
98111 const endpoint = `${ this . getBaseApiEndpoint ( ) } embed/error-page/` ;
99112
100113 const encodedOptions = [ ] ;
@@ -132,14 +145,17 @@ export class API {
132145
133146 /** Returns the ingest API endpoint for target. */
134147 private _getIngestEndpoint ( target : 'store' | 'envelope' ) : string {
148+ if ( this . _tunnel ) {
149+ return this . _tunnel ;
150+ }
135151 const base = this . getBaseApiEndpoint ( ) ;
136- const dsn = this . _dsnObject ;
152+ const dsn = this . getDsn ( ) ;
137153 return `${ base } ${ dsn . projectId } /${ target } /` ;
138154 }
139155
140156 /** Returns a URL-encoded string with auth config suitable for a query string. */
141157 private _encodedAuth ( ) : string {
142- const dsn = this . _dsnObject ;
158+ const dsn = this . getDsn ( ) ;
143159 const auth = {
144160 // We send only the minimum set of required information. See
145161 // https://github.com/getsentry/sentry-javascript/issues/2572.
0 commit comments