Skip to content

Commit 4c81399

Browse files
committed
Return url if server is already running, fixes #31
1 parent 32b98b6 commit 4c81399

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

StaticServerExample/App.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default class App extends Component<Props> {
2929
}
3030

3131
componentWillMount() {
32-
this.port = this.props.port || 0;
32+
this.port = this.props.port || 3030;
3333
this.root = this.props.root || "www/";
3434
this.file = this.props.file || './index.html';
3535

@@ -49,7 +49,7 @@ export default class App extends Component<Props> {
4949
})
5050

5151
download.promise.then(() => {
52-
// Create a StaticServer at a random port
52+
// Create a StaticServer at port 3030
5353
this.server = new StaticServer(this.port, this.root, {localOnly: true, keepAlive: true});
5454

5555
return this.server.start().then((origin) => {

index.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ class StaticServer {
5858

5959
start() {
6060
if( this.running ){
61-
return console.warn('StaticServer already running');
61+
return new new Promise((resolve, reject) => {
62+
resolve(this.origin);
63+
});
6264
}
6365

6466
this.started = true;
@@ -76,10 +78,6 @@ class StaticServer {
7678
}
7779

7880
stop() {
79-
if( !this.running ){
80-
return console.warn('StaticServer not running');
81-
}
82-
8381
this.running = false;
8482

8583
return FPStaticServer.stop();

ios/FPStaticServer.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ - (dispatch_queue_t)methodQueue
6868
self.localhost_only = localhost_only;
6969

7070
if(_webServer.isRunning != NO) {
71-
NSError *error = nil;
72-
reject(@"server_error", @"StaticServer is already up", error);
71+
NSLog(@"StaticServer already running at %@", self.url);
72+
resolve(self.url);
7373
return;
7474
}
7575

0 commit comments

Comments
 (0)