Connect to different (running) Meteor server in dev

Hi there,

Is there a way to force a meteor app to connect to a different running meteor server on the same machine in dev?
I know there is --mobile-server, but this is only working if I build for ios/android. Is there a way to achieve the same thing for a dev instance running in my standard browser?
I am currently developing a mobile app with Meteor, but I want to use my normal Chrome browser during dev, while at the same time connecting to my main meteor app, which is also running on the same machine - so basically achieving the same thing as --mobile-server does, while running in my standard Chrome browser.

Is there a way or what am I missing here?

cheers, Patrick

I suspect if you set the ROOT_URL you could trick the app into doing this - but the hot code push would probably trigger as soon as you connect and reset your running code to your production version

Just tried that, not working :frowning: - any other ideas?
I just want to avoid copying my whole server to my mobile app just for dev. Did nobody think of this usecase or am I missing something?

I’m not really sure what you mean by “copying your entire server” - your mobile app and the web app share one server in most cases, and if your local machine is accessible to your browser for dev, it should also be accessible from your phone - so long as you are on the same network.

If you’re using a real device you’ll need to use your local IP address rather than localhost, and ensure that your firewall is open on that port.

Can you share what your startup options are (port, ROOT_URL, etc) and what your setup looks like (emulator vs physical device, ios/android, mac/windows/linux)

I am not running my mobile app in any emulator/simulator/device right now - I am still in development, so I want to run my cordova app just as a normal meteor app in my Chrome browser.

At the same time I have my main app running on localhost:3000 - so I want the “mobile app” (as I said running as a normal app in my Chrome) to run without any server and just connect to my running local server at localhost:3000.

This works just fine with a cmd like this: MONGO_URL=mongodb:// meteor run ios --port 3030 --settings settings.json --mobile-server (where is my local IP in my LAN).

Thing is this is obviously starting the iOS simulator - I just want to run it in my browser - but just leaving out the ios part of my command results in ignoring the --mobile-server part of my start cmd and thus starting up its own server on port 3030.

I there a way to open my mobile app on localhost:3030, while all the subscriptions and method calls and stuff go to localhost:3000? I am thinking of monkey patching the Meteor.subscribe and methods - maybe this will work?

Ordinarily, you would just have one project that you could either run from a mobile device, or access through a browser. That would solve this problem. Separating out the mobile UI to one project, while running the server in a different project seems odd - particularly if you’re saying you want to access the mobile UI from a browser (so it is obviously not mobile dependant).

Setting ROOT_URL= doesn’t resolve this for you?

Hmm, but I think this is a lot cleaner that way?!
There has to be a way to have my mobile app in a sperate project while connecting to another meteor server, no?

To be honest, I can’t imagine why you would want to - if you were building a native app, sure, so no - I personnaly wouldn’t say it was cleaner.

Why would you want your server code to be in one project and your client code in another - how do you play to make use of optimistic UI? Will you define the verification code twice, once in the server project and once in the client project? Do you not plan on supporting browsers at all, or is your UI for mobile so different from small screen browsers - particularly considering that someone could just access your site on their phone and expect it to work. Add to this the fact that you want to do your dev in a browser, not on an emulator or physical device - and it sounds like a mess - stick to one project, unless you have exceptionally good reasons not to.

That being said - setting the ROOT_URL should work. Can you share the exact command you use to run both the server and the client projects.

So I am in the following situation:

My app (this is just the landing page) is running for a couple of months now - I have a normal meteor app running in the browser, which is also responsive and thus supports mobile --> all good.

Now I want to try some new stuff - I want to build a separate (Meteor & Cordova) mobile app, which just connects to the backend of my main meteor app. Yes, the UI is completely different and some other stuff in the frontend too.
To put it simply: my mobile app is in many ways completely different - I need a seperate project for this to do this in a clean way. Just the whole backend can stay the same!

My main app is already a god-knows-how-many-lines behemoth, I 100% do NOT want to include my new mobile app into this monolithic app as well --> separate meteor app.

Main/Backend app is run like so:
meteor run --settings settings.json :smile: nothing fancy at all - spinning up its own MongoDB, running on standard locahost:3000 - all standard!

Mobile app: I tried the following:
MONGO_URL=mongodb:// NODE_ENV=development SERVER_ENV=mobileapp meteor run --port 3030 --settings settings.json

I then tried adding ROOT_URL=http://localhost:3000 or ROOT_URL= to my cmd - both do not work and I can’t login any more or anything.

I think I got it to work - pretty hacky but fine by me I guess:

The normal way to connect to a second Meteor app is to use DDP.connect
Which connects to another DDP server (ie. Meteor) and allows you to call methods, or subscribe to publications from that server. Is that what you want?

I am aware of that! But this also results in some weird problems for me --> this.userId is often null
Any ideas on this?

Each connection has it’s own userId - make sure that your connection.userId() is set. Even then, it is possible for the client to think it has set the userId but for the server to not. This happens in the case of the connection dying and being restored, particularly if the connection is not the default meteor connection.

Our app has an admin and an enduser side. The login page is the same for both, i.e. a superset of what is needed for both sides. Once we have the user, we rely on dynamic imports to bring the rest of the code (including the templates) down.

We run these on separate servers because we need the different packages in admin and enduser. Each server is running on its own port and a shell script creates a project directory that has the different packages for the second server running a second instance of Meteor. Running Mongo standalone (as opposed to using Meteor’s default engine) allows these two servers to work on the same instance.

Even in dev, users can hop between servers because we redirect the user after adding the connect token and then use Accounts.loginWithToken client-side. Having bound potentially multiple tabs across the two servers to one login token, logging out of one will log out the others.

Our enduser app loads some code differently depending on whether it’s on mobile/Cordova or in a browser. Again we rely on dynamic imports here, but this code is served from the same (enduser) server.

The easiest way is to make two meteor apps, sharing the same Mongodb instance.

Hi, try use the DDP backend package. Just install and setup BACKEND_URL env :grinning: