From 663cc1ba01486bbeefedb8f4f884664d87d7564c Mon Sep 17 00:00:00 2001 From: Naomi Seyfer Date: Wed, 7 Aug 2013 14:09:36 -0700 Subject: [PATCH] New way of interacting with galaxy now actually binds to proxy --- packages/galaxy/.gitignore | 1 + packages/galaxy/galaxy.js | 24 ++++++----- packages/galaxy/package.js | 2 +- packages/webapp/webapp_server.js | 69 ++++++++++++++++---------------- 4 files changed, 50 insertions(+), 46 deletions(-) create mode 100644 packages/galaxy/.gitignore diff --git a/packages/galaxy/.gitignore b/packages/galaxy/.gitignore new file mode 100644 index 0000000000..b7f13992f4 --- /dev/null +++ b/packages/galaxy/.gitignore @@ -0,0 +1 @@ +.build \ No newline at end of file diff --git a/packages/galaxy/galaxy.js b/packages/galaxy/galaxy.js index 987a893eb4..745a23b32d 100644 --- a/packages/galaxy/galaxy.js +++ b/packages/galaxy/galaxy.js @@ -71,7 +71,7 @@ Galaxy.getAppConfig = function () { if (!subFuture.isResolved() && staticAppConfig) return staticAppConfig; subFuture.wait(); - var myApp = oneAppApps.findOne(); + var myApp = OneAppApps.findOne(); if (myApp) return myApp.config; throw new Error("there is no app config for this app"); @@ -93,18 +93,18 @@ Galaxy.configurePackage = function (packageName, configure) { }; var subHandle; var observed = new Future(); - Meteor.startup(function () { - // This is not required to finish, so defer it so it doesn't block anything - // else. - Meteor.defer( function () { - collectionFuture.wait(); - subHandle = OneAppApps.find().observe({ - added: configureIfDifferent, - changed: configureIfDifferent - }); - observed.return(); + + // This is not required to finish, so defer it so it doesn't block anything + // else. + Meteor.defer( function () { + collectionFuture.wait(); + subHandle = OneAppApps.find().observe({ + added: configureIfDifferent, + changed: configureIfDifferent }); + observed.return(); }); + return { stop: function () { observed.wait(); @@ -116,6 +116,8 @@ Galaxy.configurePackage = function (packageName, configure) { Galaxy.configureService = function (serviceName, configure) { if (ultra) { + collectionFuture.wait(); + console.log("subscribing to", serviceName); ultra.subscribe('servicesByName', serviceName); return Services.find({name: serviceName}).observe({ added: configure, diff --git a/packages/galaxy/package.js b/packages/galaxy/package.js index e1f661a110..4d2fb3d1be 100644 --- a/packages/galaxy/package.js +++ b/packages/galaxy/package.js @@ -3,7 +3,7 @@ Package.describe({ }); Package.on_use(function (api) { - api.use(['underscore', 'livedata']); + api.use(['underscore', 'livedata', 'ejson']); api.use(['mongo-livedata'], { unordered: true }); diff --git a/packages/webapp/webapp_server.js b/packages/webapp/webapp_server.js index 56ed6f7b69..11775ff8e7 100644 --- a/packages/webapp/webapp_server.js +++ b/packages/webapp/webapp_server.js @@ -377,6 +377,9 @@ var runWebAppServer = function () { // middlewares and update __meteor_runtime_config__, then keep going to set up // actually serving HTML. main = function (argv) { + // main happens post startup hooks, so we don't need a Meteor.startup() to + // ensure this happens after the galaxy package is loaded. + var Galaxy = Package.galaxy.Galaxy; argv = optimist(argv).boolean('keepalive').argv; var boilerplateHtmlPath = path.join(clientDir, clientJson.page); @@ -400,43 +403,41 @@ var runWebAppServer = function () { console.log("LISTENING"); // must match run.js var port = httpServer.address().port; var proxyBinding; - Meteor.startup( function () { - console.log("pre configurePackage"); - Galaxy.configurePackage('webapp', function (configuration) { - console.log("in configurePackage", 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)); + console.log("pre configurePackage"); + Galaxy.configurePackage('webapp', function (configuration) { + console.log("in configurePackage", configuration); + if (proxyBinding) + proxyBinding.stop(); + if (configuration && configuration.proxy) { + proxyBinding = Galaxy.configureService("proxy", function (proxyService) { + console.log("in configureService", 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 = configuration.proxy; + } - }); - } - }); - - var callbacks = onListeningCallbacks; - onListeningCallbacks = null; - _.each(callbacks, function (x) { x(); }); + 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);