@@ -3,28 +3,18 @@ import type { RequestHandler } from '@apollo/client';
3
3
import InstabugConstants from '../utils/InstabugConstants' ;
4
4
import xhr , { NetworkData , ProgressCallback } from '../utils/XhrNetworkInterceptor' ;
5
5
import { isContentTypeNotAllowed , reportNetworkLog } from '../utils/InstabugUtils' ;
6
- import { NativeModules } from 'react-native ' ;
6
+ import { metroDevServerPort } from './Instabug ' ;
7
7
8
8
export type { NetworkData } ;
9
9
10
10
export type NetworkDataObfuscationHandler = ( data : NetworkData ) => Promise < NetworkData > ;
11
11
let _networkDataObfuscationHandler : NetworkDataObfuscationHandler | null | undefined ;
12
12
let _requestFilterExpression = 'false' ;
13
13
14
- const filterURL = ( url : string ) : string => {
15
- const [ protocol , rest ] = url . split ( '://' ) ;
16
- return ( rest || protocol ) . split ( '/' ) [ 0 ] ;
17
- } ;
18
-
19
- const getDevServerURL = ( ) : string | null => {
20
- if ( NativeModules . SourceCode ) {
21
- const { scriptURL } = NativeModules . SourceCode ;
22
- if ( scriptURL ) {
23
- return filterURL ( scriptURL . toString ( ) ) ;
24
- }
25
- }
26
- return null ;
27
- } ;
14
+ function getPortFromUrl ( url : string ) {
15
+ const portMatch = url . match ( / : ( \d + ) (? = \/ | $ ) / ) ;
16
+ return portMatch ? portMatch [ 1 ] : null ;
17
+ }
28
18
29
19
/**
30
20
* Sets whether network logs should be sent with bug reports.
@@ -44,10 +34,8 @@ export const setEnabled = (isEnabled: boolean) => {
44
34
}
45
35
46
36
if ( __DEV__ ) {
47
- const devServerURL = getDevServerURL ( ) ;
48
- const networkServerURL = filterURL ( network . url ) ;
49
- // Skip logging for requests to the dev server
50
- if ( devServerURL === networkServerURL ) {
37
+ const urlPort = getPortFromUrl ( network . url ) ;
38
+ if ( urlPort === InstabugConstants . METRO_SERVER_URL ) {
51
39
return ;
52
40
}
53
41
}
0 commit comments