Skip to content

Commit 5e702e4

Browse files
committed
Added keepAlive option, switched to GCDWebServer on iOS
1 parent 76cd09c commit 5e702e4

File tree

70 files changed

+6851
-8330
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+6851
-8330
lines changed

android/src/main/java/com/futurepress/staticserver/FPStaticServerModule.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class FPStaticServerModule extends ReactContextBaseJavaModule implements
2929
private File www_root = null;
3030
private int port = 9999;
3131
private boolean localhost_only = false;
32+
private boolean keep_alive = false;
3233

3334
private String localPath = "";
3435
private SimpleWebServer server = null;
@@ -67,7 +68,7 @@ public String getName() {
6768
}
6869

6970
@ReactMethod
70-
public void start(String _port, String root, Boolean localhost, Promise promise) {
71+
public void start(String _port, String root, Boolean localhost, Boolean keepAlive, Promise promise) {
7172

7273
if (server != null){
7374
promise.resolve(url);
@@ -106,6 +107,10 @@ public void start(String _port, String root, Boolean localhost, Promise promise)
106107
localhost_only = localhost;
107108
}
108109

110+
if (keepAlive != null) {
111+
keep_alive = keepAlive;
112+
}
113+
109114
try {
110115

111116
if(localhost_only) {

index.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import {
22
NativeModules,
3-
AppState
3+
AppState,
4+
Platform
45
} from 'react-native';
56

67
const { FPStaticServer } = NativeModules;
78

8-
const PORT = "0";
9+
const PORT = '';
910
const ROOT = null;
1011
const LOCALHOST = 'http://127.0.0.1:';
1112

@@ -16,32 +17,38 @@ class StaticServer {
1617
this.port = `${port}` || PORT;
1718
this.root = root || ROOT;
1819
this.localOnly = (opts && opts.localOnly) || false;
20+
this.keepAlive = (opts && opts.keepAlive) || false;
1921
break;
2022
case 2:
2123
this.port = `${port}`;
2224
if (typeof(arguments[1]) === 'string') {
2325
this.root = root;
2426
this.localOnly = false;
27+
this.keepAlive = false;
2528
} else {
2629
this.root = ROOT;
2730
this.localOnly = (arguments[1] && arguments[1].localOnly) || false;
31+
this.keepAlive = (arguments[1] && arguments[1].keepAlive) || false;
2832
}
2933
break;
3034
case 1:
3135
if (typeof(arguments[0]) === 'number') {
3236
this.port = `${port}`;
3337
this.root = ROOT;
3438
this.localOnly = false;
39+
this.keepAlive = false;
3540
} else {
3641
this.port = PORT;
3742
this.root = ROOT;
3843
this.localOnly = (arguments[0] && arguments[0].localOnly) || false;
44+
this.keepAlive = (arguments[0] && arguments[0].keepAlive) || false;
3945
}
4046
break;
4147
default:
4248
this.port = PORT;
4349
this.root = ROOT;
4450
this.localOnly = false;
51+
this.keepAlive = false;
4552
}
4653

4754

@@ -56,9 +63,11 @@ class StaticServer {
5663
this.started = true;
5764
this.running = true;
5865

59-
AppState.addEventListener('change', this._handleAppStateChange.bind(this));
66+
if (!this.keepAlive && (Platform.OS === 'android')) {
67+
AppState.addEventListener('change', this._handleAppStateChange.bind(this));
68+
}
6069

61-
return FPStaticServer.start(this.port, this.root, this.localOnly);
70+
return FPStaticServer.start(this.port, this.root, this.localOnly, this.keepAlive);
6271
}
6372

6473
stop() {

ios/CocoaHTTPServer/Categories/DDData.h

Lines changed: 0 additions & 14 deletions
This file was deleted.

ios/CocoaHTTPServer/Categories/DDData.m

Lines changed: 0 additions & 158 deletions
This file was deleted.

ios/CocoaHTTPServer/Categories/DDNumber.h

Lines changed: 0 additions & 12 deletions
This file was deleted.

ios/CocoaHTTPServer/Categories/DDNumber.m

Lines changed: 0 additions & 88 deletions
This file was deleted.

0 commit comments

Comments
 (0)