From 11fccbe013f0843aa2c65850af47dadde73e1285 Mon Sep 17 00:00:00 2001 From: Naomi Seyfer Date: Mon, 5 Aug 2013 15:07:27 -0700 Subject: [PATCH] incorporating MONGO_URL into default app config --- packages/galaxy/galaxy.js | 54 ++++++++----- .../remote_collection_driver.js | 11 +-- packages/webapp/package.js | 5 +- packages/webapp/webapp_server.js | 79 ++++++++----------- tools/bundler.js | 1 - 5 files changed, 79 insertions(+), 71 deletions(-) diff --git a/packages/galaxy/galaxy.js b/packages/galaxy/galaxy.js index 42fdea8937..58701c2bbf 100644 --- a/packages/galaxy/galaxy.js +++ b/packages/galaxy/galaxy.js @@ -5,10 +5,7 @@ Galaxy = {}; Galaxy.findGalaxy = _.once(function () { if (!('GALAXY' in process.env || 'ULTRAWORLD_DDP_ENDPOINT' in process.env)) { - console.log( - "To do Meteor Galaxy operations like binding to a Galaxy " + - "proxy, the ULTRAWORLD_DDP_ENDPOINT environment variable must be set."); - process.exit(1); + return null; } return DDP.connect(process.env.GALAXY || process.env.ULTRAWORLD_DDP_ENDPOINT); @@ -20,28 +17,41 @@ Galaxy.findGalaxy = _.once(function () { var ultra = Galaxy.findGalaxy(); var subFuture = new Future(); -ultra.subscribe("oneApp", process.env.GALAXY_APP, subFuture.resolver()); +if (ultra) + ultra.subscribe("oneApp", process.env.GALAXY_APP, subFuture.resolver()); var OneAppApps; var Services; var collectionFuture = new Future(); Meteor.startup(function () { - OneAppApps = new Meteor.Collection("apps", { - connection: ultra - }); - Services = new Meteor.Collection('services', { - manager: ultra - }); - collectionFuture.return(); + if (ultra) { + OneAppApps = new Meteor.Collection("apps", { + connection: ultra + }); + Services = new Meteor.Collection('services', { + manager: ultra + }); + collectionFuture.return(); + } }); var staticAppConfig; try { - if (process.env.APP_CONFIG) + if (process.env.APP_CONFIG) { + // TODO: parse env variables into a fake app config if we don't have one. staticAppConfig = JSON.parse(process.env.APP_CONFIG); + } else { + staticAppConfig = { + packages: { + 'mongo-livedata': { + url: process.env.MONGO_URL + } + } + }; + } } catch (e) { Log.warn("Could not parse initial APP_CONFIG environment variable"); }; @@ -59,7 +69,10 @@ Galaxy.getAppConfig = function () { Galaxy.configurePackage = function (packageName, configure) { var appConfig = Galaxy.getAppConfig(); // Will either be based in the env var, // or wait for galaxy to connect. - var lastConfig = null; + var lastConfig = appConfig && appConfig.packages && appConfig.packages[packageName]; + if (lastConfig) { + configure(lastConfig); + } var configureIfDifferent = function (app) { if (!EJSON.equals(app.config && app.config.packages && app.config.packages[packageName], lastConfig)) { @@ -87,11 +100,12 @@ Galaxy.configurePackage = function (packageName, configure) { Galaxy.configureService = function (serviceName, configure) { - - ultra.subscribe('servicesByName', serviceName); - return Services.find({name: serviceName}).observe({ - added: configure, - changed: configure - }); + if (ultra) { + ultra.subscribe('servicesByName', serviceName); + return Services.find({name: serviceName}).observe({ + added: configure, + changed: configure + }); + } }; diff --git a/packages/mongo-livedata/remote_collection_driver.js b/packages/mongo-livedata/remote_collection_driver.js index 6ba05d0679..00d1b1d17a 100644 --- a/packages/mongo-livedata/remote_collection_driver.js +++ b/packages/mongo-livedata/remote_collection_driver.js @@ -22,11 +22,12 @@ _.extend(MongoInternals.RemoteCollectionDriver.prototype, { // only require Mongo configuration if it's actually used (eg, not if // you're only trying to receive data from a remote DDP server.) MongoInternals.defaultRemoteCollectionDriver = _.once(function () { - // XXX kind of hacky - var mongoUrl = ( - typeof __meteor_bootstrap__ !== 'undefined' && - Meteor._get(__meteor_bootstrap__, - 'deployConfig', 'packages', 'mongo-livedata', 'url')); + var mongoUrl; + Galaxy.configurePackage("mongo-livedata", function (config) { + // This will keep running if mongo gets reconfigured. That's not ideal, but + // should be ok for now. + mongoUrl = config.url; + }); // XXX bad error since it could also be set directly in METEOR_DEPLOY_CONFIG if (! mongoUrl) throw new Error("MONGO_URL must be set in environment"); diff --git a/packages/webapp/package.js b/packages/webapp/package.js index 1b1da1c895..0db28dec11 100644 --- a/packages/webapp/package.js +++ b/packages/webapp/package.js @@ -8,7 +8,10 @@ Npm.depends({connect: "2.7.10", useragent: "2.0.1"}); Package.on_use(function (api) { - api.use(['logging', 'underscore', 'routepolicy', 'galaxy'], 'server'); + api.use(['logging', 'underscore', 'routepolicy'], 'server'); + api.use(['galaxy'], { + unordered: true + }); api.export(['WebApp', 'main', 'WebAppInternals'], 'server'); api.add_files('webapp_server.js', 'server'); }); diff --git a/packages/webapp/webapp_server.js b/packages/webapp/webapp_server.js index ed61f9ba60..e9180bcf10 100644 --- a/packages/webapp/webapp_server.js +++ b/packages/webapp/webapp_server.js @@ -15,17 +15,6 @@ var send = Npm.require('send'); WebApp = {}; WebAppInternals = {}; -var findGalaxy = _.once(function () { - if (!('GALAXY' in process.env)) { - console.log( - "To do Meteor Galaxy operations like binding to a Galaxy " + - "proxy, the GALAXY environment variable must be set."); - process.exit(1); - } - - return DDP.connect(process.env['GALAXY']); -}); - // Keepalives so that when the outer server dies unceremoniously and // doesn't kill us, we quit ourselves. A little gross, but better than // pidfiles. @@ -447,42 +436,44 @@ var runWebAppServer = function () { console.log("LISTENING"); // must match run.js var port = httpServer.address().port; var proxyBinding; - Galaxy.configurePackage('webapp', function (configuration) { - if (proxyBinding) - proxyBinding.stop(); - if (configuration && configuration.proxy) { - proxyBinding = Galaxy.configureService(function (proxyService) { - if (proxyService.providers.proxy) { - var proxyConf; - if (process.env.ADMIN_APP) { - proxyConf = { - securePort: null, - insecurePort: 9414, - bindHost: "localhost", - bindPathPrefix: "/" + process.env.GALAXY_APP - }; - } else { - proxyConf = { - // TODO: allow sitename to be a list. - bindHost: configuration.proxy.sitename - }; + Meteor.startup( function () { + Galaxy.configurePackage('webapp', function (configuration) { + if (proxyBinding) + proxyBinding.stop(); + if (configuration && configuration.proxy) { + proxyBinding = Galaxy.configureService(function (proxyService) { + if (proxyService.providers.proxy) { + var proxyConf; + if (process.env.ADMIN_APP) { + proxyConf = { + securePort: null, + insecurePort: 9414, + bindHost: "localhost", + bindPathPrefix: "/" + process.env.GALAXY_APP + }; + } else { + proxyConf = { + // TODO: allow sitename to be a list. + bindHost: configuration.proxy.sitename + }; + } + Log("Attempting to bind to proxy at " + proxyService.providers.proxy); + WebAppInternals.bindToProxy(_.extend({ + proxyEndpoint: proxyService.providers.proxy + }, proxyConf)); } - Log("Attempting to bind to proxy at " + proxyService.providers.proxy); - WebAppInternals.bindToProxy(_.extend({ - proxyEndpoint: proxyService.providers.proxy - }, proxyConf)); - } - }); - } - }); + }); + } + }); - var callbacks = onListeningCallbacks; - onListeningCallbacks = null; - _.each(callbacks, function (x) { x(); }); - }, function (e) { - console.error("Error listening:", e); - console.error(e.stack); + var callbacks = onListeningCallbacks; + onListeningCallbacks = null; + _.each(callbacks, function (x) { x(); }); + }, function (e) { + console.error("Error listening:", e); + console.error(e.stack); + }); })); if (argv.keepalive) diff --git a/tools/bundler.js b/tools/bundler.js index bbdbb0bc9f..3216ef8c2b 100644 --- a/tools/bundler.js +++ b/tools/bundler.js @@ -543,7 +543,6 @@ _.extend(Target.prototype, { // strong dependency on it, then ignore this edge. if (useOptions.weak && ! _.has(getsUsed, usedSlice.id)) return; - if (onStack[usedSlice.id]) { buildmessage.error("circular dependency between packages " + slice.pkg.name + " and " + usedSlice.pkg.name);