diff --git a/packages/application-configuration/config.js b/packages/application-configuration/config.js index 7268dc2ae8d..25c3c19a275 100644 --- a/packages/application-configuration/config.js +++ b/packages/application-configuration/config.js @@ -149,15 +149,50 @@ AppConfig.configurePackage = function (packageName, configure) { }; }; -AppConfig.configureService = function (serviceName, configure) { +AppConfig.configureService = function (serviceName, version, configure) { + + // Collect all the endpoints for this service, from both old- and new-format + // documents, and call the `configure` callback with all the service endpoints + // that we know about. + var callConfigure = function (doc) { + var serviceDocs = Services.find({ + name: serviceName, + version: version + }); + var endpoints = []; + serviceDocs.forEach(function (serviceDoc) { + if (serviceDoc.providers) { + _.each(serviceDoc.providers, function (endpoint, app) { + endpoints.push(endpoint); + }); + } else { + endpoints.push(serviceDoc.endpoint); + } + }); + configure(endpoints); + }; + if (ultra) { // there's a Meteor.startup() that produces the various collections, make // sure it runs first before we continue. collectionFuture.wait(); - ultra.subscribe('servicesByName', serviceName); - return Services.find({name: serviceName}).observe({ - added: configure, - changed: configure + // First try to subscribe to the new format service registrations; if that + // sub doesn't exist, then ultraworld hasn't updated to the new format yet, + // so try the old format `servicesByName` sub instead. + ultra.subscribe('services', serviceName, version, { + onError: function (err) { + if (err.error === 404) { + ultra.subscribe('servicesByName', serviceName); + } + } + }); + return Services.find({ + name: serviceName, + version: version + }).observe({ + added: callConfigure, + changed: callConfigure, + removed: callConfigure }); } diff --git a/packages/ctl-helper/ctl-helper.js b/packages/ctl-helper/ctl-helper.js index 355583cb7e1..4806ddcc7a2 100644 --- a/packages/ctl-helper/ctl-helper.js +++ b/packages/ctl-helper/ctl-helper.js @@ -139,18 +139,20 @@ _.extend(Ctl, { updateProxyActiveTags: function (tags) { var proxy; var proxyTagSwitchFuture = new Future; - AppConfig.configureService('proxy', function (proxyService) { - try { - proxy = Follower.connect(proxyService.providers.proxy, { - group: "proxy" - }); - proxy.call('updateTags', Ctl.myAppName(), tags); - proxy.disconnect(); - if (!proxyTagSwitchFuture.isResolved()) - proxyTagSwitchFuture['return'](); - } catch (e) { - if (!proxyTagSwitchFuture.isResolved()) - proxyTagSwitchFuture['throw'](e); + AppConfig.configureService('proxy', 'pre0', function (proxyService) { + if (proxyService && ! _.isEmpty(proxyService)) { + try { + proxy = Follower.connect(proxyService, { + group: "proxy" + }); + proxy.call('updateTags', Ctl.myAppName(), tags); + proxy.disconnect(); + if (!proxyTagSwitchFuture.isResolved()) + proxyTagSwitchFuture['return'](); + } catch (e) { + if (!proxyTagSwitchFuture.isResolved()) + proxyTagSwitchFuture['throw'](e); + } } }); diff --git a/packages/webapp/webapp_server.js b/packages/webapp/webapp_server.js index f647f967467..d8d6f282780 100644 --- a/packages/webapp/webapp_server.js +++ b/packages/webapp/webapp_server.js @@ -580,8 +580,9 @@ var runWebAppServer = function () { // on a per-job basis. Discuss w/ teammates. proxyBinding = AppConfig.configureService( "proxy", + "pre0", function (proxyService) { - if (proxyService.providers.proxy) { + if (proxyService && ! _.isEmpty(proxyService)) { var proxyConf; // XXX Figure out a per-job way to specify bind location // (besides hardcoding the location for ADMIN_APP jobs). @@ -602,9 +603,9 @@ var runWebAppServer = function () { proxyConf = configuration.proxy; } Log("Attempting to bind to proxy at " + - proxyService.providers.proxy); + proxyService); WebAppInternals.bindToProxy(_.extend({ - proxyEndpoint: proxyService.providers.proxy + proxyEndpoint: proxyService }, proxyConf)); } }