In need of some architectural advice on how to create an Mobile app with a back-end web portal


#1

Hi all!

I’m a meteor newbie but my love for meteor is growing by the minute. :wink:

I’m planning on developing a mobile app using Cordova/PhoneGap (and meteor of course).
The system will also include a web portal as a back-end, but I’m unsure of how to structure this the best way.

Should I create two separate meteor projects (one for the mobile app and one for the back-end portal), and somehow connect both “apps” to the same database? If so, I guess I won’t be able to reuse the serverside logic, which is a bummer.

Or could I develop both the app and the back-end in one meteor-project? If so, what about packaging and deployment to the app store? There’s no point including the back-end in the app - is there some way of avoiding that?

Any other options?

I hope some of you could shed some light on this for me, and that the answer is not embarrasingly obvious…

Regards,
Jon


#2

I am also trying to get this to work. I have a web based app, that i want to work differently from my mobile app.

Locally, I am able to connect to a remote db (on meteor.com) via these commands (lots of helpful posts for this):

$ meteor mongo --url http://blah.meteor.com/

mongodb://client-ca3bxae5:b05dx2ae-1da1-a82b-45b7-bc35b4b11ed9@production-db-a2.meteor.io:27017/blah_meteor_com

then copy the output mongodb url to my path as:

$ MONGO_URL='mongodb://client-ca3bxae5:b05dx2ae-1da1-a82b-45b7-bc35b4b11ed9@production-db-a2.meteor.io:27017/blah_meteor_com' meteor run --port 8000

Works great.

My problem is, how do I generate a mobile app (android or ios), with the mongo_url?

I tried adding this to my project (folder: /lib file:config.js)

Meteor.startup(function () {
    process.env.MONGO_URL = 'mongodb://user:password@roduction-db-a2.meteor.io:27017/blah_meteor_com';
});

I then start the app like this:

$ meteor --port 8000

But no dice. I also send the env vars to the console to review. (folder: server)

Meteor.startup(function () {
   console.log(process.env);    
});

Result:

I20150409-10:04:57.118(-5)? { TERM_PROGRAM: 'Apple_Terminal',
...
I20150409-10:04:57.120(-5)?   MONGO_URL: 'mongodb://user:password@production-db-a2.meteor.io:27017/blah_meteor_com',
...
I20150409-10:04:57.121(-5)?   ROOT_URL: 'http://localhost:8000/',
I20150409-10:04:57.121(-5)?   MOBILE_DDP_URL: 'http://localhost:8000',
I20150409-10:04:57.121(-5)?   MOBILE_ROOT_URL: 'http://localhost:8000',
I20150409-10:04:57.121(-5)?   NODE_ENV: 'development',
I20150409-10:04:57.121(-5)?   HTTP_FORWARDED_COUNT: '1',
I20150409-10:04:57.122(-5)?   METEOR_SHELL_DIR: '/Users/ME/Desktop/Meteor/demo/.meteor/local/shell',
I20150409-10:04:57.122(-5)?   METEOR_PARENT_PID: '84523',
I20150409-10:04:57.122(-5)?   METEOR_PRINT_ON_LISTEN: 'true',
I20150409-10:04:57.122(-5)?   NODE_PATH: '' }

I have reviewed many links and sites for this, but i just can’t connect to a remote mongodb, w/o using env variables.

Any thoughts?


#3

The documentation for Meteor.startup says “On a server, the function will run as soon as the server process is finished starting”, so I suspect that by the time you have overwritten process.env.MONGO_URL it’s too late - the database has already been opened.

What happens if you ensure your code runs before the startup callback is executed?


#4

I took out the Meteor.startup out of the file. Changed the filename to main.js. Meteor documentation says files named with “main” get loaded first.

/lib/main.js looks like this now: (only one line)

process.env.MONGO_URL = 'mongodb://user:password@production-db-a2.meteor.io:27017/user_meteor_com';

(user and password masked)

This did not work. I’m still not able to talk to the remote meteor db. I also tried to connect to a local mongodb running on a different port.

process.env.MONGO_URL = 'mongodb://127.0.0.1:3001/meteor';

Also did not work.
When I run console.log(process.env) on the server, it appears that the env variable is set correctly, but wont connect.


#5

Actually, the Meteor documentation says:

  1. HTML template files are always loaded before everything else
  2. Files beginning with main. are loaded last
  3. Files inside any lib/ directory are loaded next
  4. Files with deeper paths are loaded next
  5. Files are then loaded in alphabetical order of the entire path

So, depending on the complexity (depth) of your lib/ directory, I would be inclined to try something like:

lib/00.js: (Move the loading of this to the front. You may need a deeper folder - see rule 4)

if (Meteor.isServer) {
  process.env.MONGO_URL = 'mongodb://user:password@production-db-a2.meteor.io:27017/user_meteor_com';
}

I have to say that even if this works it’s a kludge and therefore fragile.

If not, I’m going Internet-less for the next 10 days (something known as a “vacation” :wink: ) and won’t be able to investigate further. Hopefully, someone else will have the right answer!


#6

Tried all your suggestions. But no luck still. Again, no problems when using the env variable.

I guess I need to keep searching.