Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple servers? #94

Open
jtreat3 opened this issue Sep 4, 2020 · 5 comments
Open

Multiple servers? #94

jtreat3 opened this issue Sep 4, 2020 · 5 comments

Comments

@jtreat3
Copy link

jtreat3 commented Sep 4, 2020

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.

@JowelTisso
Copy link

@jtreat3 :Have you solved this issue?

@JowelTisso
Copy link

@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...

@jtreat3
Copy link
Author

jtreat3 commented Mar 16, 2021

I thought I had stored it as a local variable, but it was too long ago to remember.
Thanks @JowelTisso.

@noway
Copy link

noway commented Jun 21, 2021

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.

@KennanChan
Copy link

I am wondering why the _webServer is designed to be a singleton? Any platform restriction on iOS?

smellman pushed a commit to smellman/react-native-static-server that referenced this issue Sep 25, 2024
with the latest react-native-webview@13.6.4 it builds, and works, at
least in the dev mode.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants