Skip to content

Commit c1097d2

Browse files
committed
Update ios to reject if serverUrl is null
1 parent 64f2cf3 commit c1097d2

File tree

4 files changed

+51
-14
lines changed

4 files changed

+51
-14
lines changed

StaticServerExample/App.js

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
View,
1313
WebView,
1414
Image,
15+
NativeModules
1516
} from 'react-native';
1617

1718
import StaticServer from 'react-native-static-server';
@@ -31,30 +32,47 @@ export default class App extends Component<Props> {
3132
componentWillMount() {
3233
this.port = this.props.port || 3030;
3334
this.root = this.props.root || "www/";
34-
this.file = this.props.file || './index.html';
35+
this.file = this.props.file || 'index.html';
3536

3637
// Get HTML file from require
3738
let html = require('./index.html');
3839
let {uri} = Image.resolveAssetSource(html);
3940

40-
let path = RNFS.DocumentDirectoryPath + '/www';
41+
let path = RNFS.DocumentDirectoryPath + "/" + this.root;
42+
let dest = path + this.file;
4143

4244
// Add the directory
4345
RNFS.mkdir(path, { NSURLIsExcludedFromBackupKey: true });
4446

4547
// Fetch the file
46-
let download = RNFS.downloadFile({
47-
fromUrl: uri,
48-
toFile: path + "/index.html"
49-
})
48+
let added;
49+
50+
if (uri.indexOf("file://") > -1) {
51+
// Copy file in release
52+
added = RNFS.exists(dest).then((e) => {
53+
if (!e) {
54+
return RNFS.copyFile(uri, dest);
55+
}
56+
});
57+
} else {
58+
// Download for development
59+
let download = RNFS.downloadFile({
60+
fromUrl: uri,
61+
toFile: dest
62+
});
63+
added = download.promise;
64+
}
65+
5066

51-
download.promise.then(() => {
67+
added.then(() => {
5268
// Create a StaticServer at port 3030
53-
this.server = new StaticServer(this.port, this.root, {localOnly: true, keepAlive: true});
69+
this.server = new StaticServer(this.port, this.root, {localOnly: true});
5470

55-
return this.server.start().then((origin) => {
71+
this.server.start().then((origin) => {
5672
this.setState({origin});
5773
});
74+
}).catch((err) => {
75+
console.error(err);
5876
})
5977

6078
}
@@ -77,7 +95,7 @@ export default class App extends Component<Props> {
7795

7896
return (
7997
<WebView
80-
source={{uri: `${this.state.origin}/index.html`}}
98+
source={{uri: `${this.state.origin}/${this.file}`}}
8199
style={styles.webview}
82100
/>
83101
);

StaticServerExample/ios/StaticServerExample.xcodeproj/project.pbxproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,14 +746,20 @@
746746
TargetAttributes = {
747747
00E356ED1AD99517003FC87E = {
748748
CreatedOnToolsVersion = 6.2;
749+
DevelopmentTeam = S9PLTSRA52;
749750
TestTargetID = 13B07F861A680F5B00A75B9A;
750751
};
752+
13B07F861A680F5B00A75B9A = {
753+
DevelopmentTeam = S9PLTSRA52;
754+
};
751755
2D02E47A1E0B4A5D006451C7 = {
752756
CreatedOnToolsVersion = 8.2.1;
757+
DevelopmentTeam = S9PLTSRA52;
753758
ProvisioningStyle = Automatic;
754759
};
755760
2D02E48F1E0B4A5D006451C7 = {
756761
CreatedOnToolsVersion = 8.2.1;
762+
DevelopmentTeam = S9PLTSRA52;
757763
ProvisioningStyle = Automatic;
758764
TestTargetID = 2D02E47A1E0B4A5D006451C7;
759765
};
@@ -1253,6 +1259,7 @@
12531259
isa = XCBuildConfiguration;
12541260
buildSettings = {
12551261
BUNDLE_LOADER = "$(TEST_HOST)";
1262+
DEVELOPMENT_TEAM = S9PLTSRA52;
12561263
GCC_PREPROCESSOR_DEFINITIONS = (
12571264
"DEBUG=1",
12581265
"$(inherited)",
@@ -1284,6 +1291,7 @@
12841291
buildSettings = {
12851292
BUNDLE_LOADER = "$(TEST_HOST)";
12861293
COPY_PHASE_STRIP = NO;
1294+
DEVELOPMENT_TEAM = S9PLTSRA52;
12871295
HEADER_SEARCH_PATHS = (
12881296
"$(inherited)",
12891297
"$(SRCROOT)/../node_modules/react-native-static-server/ios/**",
@@ -1312,6 +1320,7 @@
13121320
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
13131321
CURRENT_PROJECT_VERSION = 1;
13141322
DEAD_CODE_STRIPPING = NO;
1323+
DEVELOPMENT_TEAM = S9PLTSRA52;
13151324
HEADER_SEARCH_PATHS = (
13161325
"$(inherited)",
13171326
"$(SRCROOT)/../node_modules/react-native-static-server/ios/**",
@@ -1337,6 +1346,7 @@
13371346
buildSettings = {
13381347
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
13391348
CURRENT_PROJECT_VERSION = 1;
1349+
DEVELOPMENT_TEAM = S9PLTSRA52;
13401350
HEADER_SEARCH_PATHS = (
13411351
"$(inherited)",
13421352
"$(SRCROOT)/../node_modules/react-native-static-server/ios/**",
@@ -1367,6 +1377,7 @@
13671377
CLANG_WARN_INFINITE_RECURSION = YES;
13681378
CLANG_WARN_SUSPICIOUS_MOVE = YES;
13691379
DEBUG_INFORMATION_FORMAT = dwarf;
1380+
DEVELOPMENT_TEAM = S9PLTSRA52;
13701381
ENABLE_TESTABILITY = YES;
13711382
GCC_NO_COMMON_BLOCKS = YES;
13721383
HEADER_SEARCH_PATHS = (
@@ -1404,6 +1415,7 @@
14041415
CLANG_WARN_SUSPICIOUS_MOVE = YES;
14051416
COPY_PHASE_STRIP = NO;
14061417
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
1418+
DEVELOPMENT_TEAM = S9PLTSRA52;
14071419
GCC_NO_COMMON_BLOCKS = YES;
14081420
HEADER_SEARCH_PATHS = (
14091421
"$(inherited)",
@@ -1438,6 +1450,7 @@
14381450
CLANG_WARN_INFINITE_RECURSION = YES;
14391451
CLANG_WARN_SUSPICIOUS_MOVE = YES;
14401452
DEBUG_INFORMATION_FORMAT = dwarf;
1453+
DEVELOPMENT_TEAM = S9PLTSRA52;
14411454
ENABLE_TESTABILITY = YES;
14421455
GCC_NO_COMMON_BLOCKS = YES;
14431456
INFOPLIST_FILE = "StaticServerExample-tvOSTests/Info.plist";
@@ -1465,6 +1478,7 @@
14651478
CLANG_WARN_SUSPICIOUS_MOVE = YES;
14661479
COPY_PHASE_STRIP = NO;
14671480
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
1481+
DEVELOPMENT_TEAM = S9PLTSRA52;
14681482
GCC_NO_COMMON_BLOCKS = YES;
14691483
INFOPLIST_FILE = "StaticServerExample-tvOSTests/Info.plist";
14701484
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";

StaticServerExample/ios/StaticServerExample.xcodeproj/xcshareddata/xcschemes/StaticServerExample.xcscheme

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
buildConfiguration = "Debug"
5555
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
5656
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
57+
language = ""
5758
shouldUseLaunchSchemeArgsEnv = "YES">
5859
<Testables>
5960
<TestableReference
@@ -83,6 +84,7 @@
8384
buildConfiguration = "Debug"
8485
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
8586
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
87+
language = ""
8688
launchStyle = "0"
8789
useCustomWorkingDirectory = "NO"
8890
ignoresPersistentStateOnLaunch = "NO"

ios/FPStaticServer.m

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,14 @@ - (dispatch_queue_t)methodQueue
100100
if([_webServer startWithOptions:options error:&error]) {
101101
NSNumber *listenPort = [NSNumber numberWithUnsignedInteger:_webServer.port];
102102
self.port = listenPort;
103-
self.url = [NSString stringWithFormat: @"%@://%@:%@", [_webServer.serverURL scheme], [_webServer.serverURL host], [_webServer.serverURL port]];
104-
NSLog(@"Started StaticServer at URL %@", self.url);
105103

106-
resolve(self.url);
107-
104+
if(_webServer.serverURL == NULL) {
105+
reject(@"server_error", @"StaticServer could not start", error);
106+
} else {
107+
self.url = [NSString stringWithFormat: @"%@://%@:%@", [_webServer.serverURL scheme], [_webServer.serverURL host], [_webServer.serverURL port]];
108+
NSLog(@"Started StaticServer at URL %@", self.url);
109+
resolve(self.url);
110+
}
108111
} else {
109112
NSLog(@"Error starting StaticServer: %@", error);
110113

0 commit comments

Comments
 (0)