1
1
import type { Event , EventHint } from '@sentry/types' ;
2
+ import { GLOBAL_OBJ } from '@sentry/utils' ;
2
3
import type { StackFrame } from 'stacktrace-parser' ;
3
4
import * as stackTraceParser from 'stacktrace-parser' ;
4
5
@@ -8,6 +9,10 @@ type OriginalStackFrameResponse = {
8
9
sourcePackage ?: string ;
9
10
} ;
10
11
12
+ const globalWithInjectedValues = GLOBAL_OBJ as typeof GLOBAL_OBJ & {
13
+ __sentryBasePath ?: string ;
14
+ } ;
15
+
11
16
async function resolveStackFrame (
12
17
frame : StackFrame ,
13
18
error : Error ,
@@ -26,13 +31,20 @@ async function resolveStackFrame(
26
31
params . append ( key , ( frame [ key as keyof typeof frame ] ?? '' ) . toString ( ) ) ;
27
32
} ) ;
28
33
34
+ let basePath = globalWithInjectedValues . __sentryBasePath ?? '' ;
35
+
36
+ // Prefix the basepath with a slash if it doesn't have one
37
+ if ( basePath !== '' && ! basePath . match ( / ^ \/ / ) ) {
38
+ basePath = `/${ basePath } ` ;
39
+ }
40
+
29
41
const controller = new AbortController ( ) ;
30
42
const timer = setTimeout ( ( ) => controller . abort ( ) , 3000 ) ;
31
43
const res = await fetch (
32
44
`${
33
45
// eslint-disable-next-line no-restricted-globals
34
46
typeof window === 'undefined' ? 'http://localhost:3000' : '' // TODO: handle the case where users define a different port
35
- } /__nextjs_original-stack-frame?${ params . toString ( ) } `,
47
+ } ${ basePath } /__nextjs_original-stack-frame?${ params . toString ( ) } `,
36
48
{
37
49
signal : controller . signal ,
38
50
} ,
0 commit comments