Switch server connection during runtime

I’m running a separate Meteor instance on my server for each company that uses my app. Each company uses it’s own subdomain in the url, and I’m running Nginx as a reverse proxy to forward them to the right instance. This works great for the browser, as you simply go to “mysubdomain.theapp.com” but now that I’m starting on the Cordova app, I’m not sure how to do it, since you only specify the url during the build.

Is there like a global setting in either Cordova or Meteor that can be changed at runtime?
I know you can use DDP.connect() to subscribe to collections on a different server, but I’m not sure how to do a “complete” connection switch for the whole app.

Have you seen this video about ReactNative and Meteor? Maybe that could be a solution because it allows to connect to a specific Meteor ws:// URL. You could have an intermediary step where a user who has downloaded the app from the App Store needs to go and perform a one-time registration step that provides the mobile app the correct URL to connect to …

Hmm, my app is built with Blaze though :confused: And it’s pretty big so it’d be a lot of work to remake it in React.

Yeah it’s no problem if it connects to the default server initially, and then the user can pick a server. I just don’t know how to do it. I found some discussions about it, and even a server-picker package on Atmosphere, but it seemed to be outdated. I’d be fine with it breaking hot code push maybe, if I could just change the default connection for all subscriptions and accounts.

This is a design problem currently being tackled and I would also like a solution for this


is there a recommended solution for this? I am using Cordova and the video above works with react native. thank you!

I used this: https://github.com/partus/meteor-server-picker (https://atmospherejs.com/feit/server-picker)
and I set window.localStorage.setItem("__root_url",“http://yourOtherServer.com”)

I kept getting a No ‘Access-Control-Allow-Origin’ header is present on the requested resource. which took me an embarrassing amount of time to realize I needed https in the above (for window.localStorage.setItem("__root_url",“https://yourOtherServer.com”). then it all worked.

1 Like

Very nice, worked for me too!