react-native-static-server
react-native-static-server copied to clipboard
Multiple servers?
Thanks for this server. Great work!
I'm wondering if it's possible to run two servers at once. So far, it looks like if I try, even though the port property of each instance is different and correct, the url returned upon starting both uses only the first port, and it seems like nothing is actually served to the second port.
My goal with two servers is to be able to serve both the assets bundled in my app as well as assets saved by the app (which seemingly must be stored in another location). Thanks.
@jtreat3 :Have you solved this issue?
@jtreat3 In case if you have not solved this issue or anyone else... I was facing this issue cause I was trying to store the newServer instance in a useState which was not saved for some reason... So I was not able to kill it in component unmount or any other case... So I used a local variable to save the instance of newServer then i was able to kill the server from that local variable... This is all which solved my problem... Hope it helps...
I thought I had stored it as a local variable, but it was too long ago to remember. Thanks @JowelTisso.
This package doesn't support multiple servers. The FPStaticServer
(underlying native module) is a singleton, and these are the methods it exposes:
- start
- stop
- isRunning
calling start multiple times is not supported:
if(_webServer.isRunning != NO) {
NSLog(@"StaticServer already running at %@", self.url);
resolve(self.url);
return;
}
The exposed javascript API is confusing, making you believe you can instantiate multiple server instances. This is not the case. You will get the same server when you call start
the second time, even though the javascript instance will appear to hold the values you've specified (_origin will be different though and the only property telling the truth).
I wish we were exposed only the FPStaticServer API. The javascript API is misleading.
I am wondering why the _webServer is designed to be a singleton? Any platform restriction on iOS?