File tree Expand file tree Collapse file tree 3 files changed +49
-9
lines changed
JavaScriptAppEngine/Initialization Expand file tree Collapse file tree 3 files changed +49
-9
lines changed Original file line number Diff line number Diff line change @@ -20,11 +20,11 @@ var Text = require('Text');
2020var TouchableHighlight = require ( 'TouchableHighlight' ) ;
2121var TouchableWithoutFeedback = require ( 'TouchableWithoutFeedback' ) ;
2222var View = require ( 'View' ) ;
23- var { SourceCode} = require ( 'NativeModules' ) ;
2423var { fetch} = require ( 'fetch' ) ;
2524
2625var flattenStyle = require ( 'flattenStyle' ) ;
2726var mapWithSeparator = require ( 'mapWithSeparator' ) ;
27+ var getDevServer = require ( 'getDevServer' ) ;
2828
2929var ElementProperties = React . createClass ( {
3030 propTypes : {
@@ -97,10 +97,7 @@ var ElementProperties = React.createClass({
9797 } ,
9898
9999 _openFile : function ( fileName : string , lineNumber : number ) {
100- var match = SourceCode . scriptURL && SourceCode . scriptURL . match ( / ^ h t t p s ? : \/ \/ .* ?\/ / ) ;
101- var baseURL = match ? match [ 0 ] : 'http://localhost:8081/' ;
102-
103- fetch ( baseURL + 'open-stack-frame' , {
100+ fetch ( getDevServer ( ) . url + 'open-stack-frame' , {
104101 method : 'POST' ,
105102 body : JSON . stringify ( { file : fileName , lineNumber} ) ,
106103 } ) ;
Original file line number Diff line number Diff line change @@ -35,12 +35,15 @@ function reportException(e: Error, isFatal: bool) {
3535}
3636
3737function symbolicateAndUpdateStack ( id , message , stack ) {
38+ const getDevServer = require ( 'getDevServer' ) ;
3839 const { fetch} = require ( 'fetch' ) ;
39- const { SourceCode, ExceptionsManager} = require ( 'NativeModules' ) ;
40- const match = SourceCode . scriptURL && SourceCode . scriptURL . match ( / ^ h t t p s ? : \/ \/ .* ?\/ / ) ;
41- const endpoint = ( match && match [ 0 ] : 'http://localhost:8081/' ) + 'symbolicate' ;
40+ const { ExceptionsManager} = require ( 'NativeModules' ) ;
41+ const devServer = getDevServer ( ) ;
42+ if ( ! devServer . bundleLoadedFromServer ) {
43+ return ;
44+ }
4245
43- fetch ( endpoint , { method : 'POST' , body : JSON . stringify ( { stack} ) } )
46+ fetch ( devServer . url + 'symbolicate' , { method : 'POST' , body : JSON . stringify ( { stack} ) } )
4447 . then ( response => response . json ( ) )
4548 . then ( response =>
4649 ExceptionsManager . updateExceptionMessage ( message , response . stack , id ) )
Original file line number Diff line number Diff line change 1+ /**
2+ * Copyright (c) 2015-present, Facebook, Inc.
3+ * All rights reserved.
4+ *
5+ * This source code is licensed under the BSD-style license found in the
6+ * LICENSE file in the root directory of this source tree. An additional grant
7+ * of patent rights can be found in the PATENTS file in the same directory.
8+ *
9+ * @providesModule getDevServer
10+ * @flow
11+ */
12+ 'use strict' ;
13+
14+ const { SourceCode} = require ( 'NativeModules' ) ;
15+
16+ let _cachedDevServerURL : ?string ;
17+ const FALLBACK = 'http://localhost:8081/' ;
18+
19+ type DevServerInfo = {
20+ url : string ;
21+ bundleLoadedFromServer: boolean ;
22+ } ;
23+
24+ /**
25+ * Many RN development tools rely on the development server (packager) running
26+ * @return URL to packager with trailing slash
27+ */
28+ function getDevServer ( ) : DevServerInfo {
29+ if ( _cachedDevServerURL === undefined ) {
30+ const match = SourceCode . scriptURL && SourceCode . scriptURL . match ( / ^ h t t p s ? : \/ \/ .* ?\/ / ) ;
31+ _cachedDevServerURL = match ? match [ 0 ] : null ;
32+ }
33+
34+ return {
35+ url : _cachedDevServerURL || FALLBACK ,
36+ bundleLoadedFromServer : _cachedDevServerURL !== null ,
37+ } ;
38+ }
39+
40+ module . exports = getDevServer ;
You can’t perform that action at this time.
0 commit comments