From be70f2884644eda77750794ce15f428481aeac5c Mon Sep 17 00:00:00 2001 From: witmicko Date: Thu, 25 Aug 2016 17:08:30 +0100 Subject: [PATCH 1/2] lazy load aero gear --- lib/push.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/push.js b/lib/push.js index d0cedd3..c5570c2 100644 --- a/lib/push.js +++ b/lib/push.js @@ -1,6 +1,6 @@ -var AeroGear = require("unifiedpush-node-sender"), - assert = require('assert'), - futils = require('./fhutils'); +var assert = require('assert'), + futils = require('./fhutils'), + aeroGearLoaded = false; module.exports = function (cfg) { assert.ok(cfg, 'cfg is undefined'); @@ -9,7 +9,7 @@ module.exports = function (cfg) { var props = fhutils.getMillicoreProps(); var headers = { 'X-Project-Id': props.widget, - 'X-App-Id': props.instance, + 'X-App-Id': props.instance }; fhutils.addAppApiKeyHeader(headers); var settings = { @@ -19,16 +19,24 @@ module.exports = function (cfg) { headers: headers }; - var sender = AeroGear.Sender(settings); // $fh.push + var sender; return function push(message, options, callback) { + if (!aeroGearLoaded) { + AeroGear = require("unifiedpush-node-sender"); + sender = AeroGear.Sender(settings); + aeroGearLoaded = true; + } + if (!message) return callback(new Error("Missing required 'message' parameter")); if (!options) return callback(new Error("Missing required 'options' parameter")); if (!options.broadcast) { if (!options.apps) return callback(new Error("Missing required 'options.apps' parameter while 'options.broadcast' not specified" + JSON.stringify(options))); } - sender.send(message, options, callback); + if (sender){ + sender.send(message, options, callback); + } } }; From 78ab905e26565a06f2ed4cbb96ef61455ddbef35 Mon Sep 17 00:00:00 2001 From: witmicko Date: Thu, 25 Aug 2016 17:09:29 +0100 Subject: [PATCH 2/2] version bump --- lib/push.js | 2 +- npm-shrinkwrap.json | 2 +- package.json | 2 +- sonar-project.properties | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/push.js b/lib/push.js index c5570c2..207753f 100644 --- a/lib/push.js +++ b/lib/push.js @@ -24,7 +24,7 @@ module.exports = function (cfg) { var sender; return function push(message, options, callback) { if (!aeroGearLoaded) { - AeroGear = require("unifiedpush-node-sender"); + var AeroGear = require("unifiedpush-node-sender"); sender = AeroGear.Sender(settings); aeroGearLoaded = true; } diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index c285d01..712f793 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -1,6 +1,6 @@ { "name": "fh-mbaas-api", - "version": "5.13.8", + "version": "5.13.9", "dependencies": { "async": { "version": "0.2.9", diff --git a/package.json b/package.json index d313da9..13eb145 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fh-mbaas-api", - "version": "5.13.8", + "version": "5.13.9", "description": "FeedHenry MBAAS Cloud APIs", "main": "lib/api.js", "dependencies": { diff --git a/sonar-project.properties b/sonar-project.properties index 598363a..14c15af 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -1,6 +1,6 @@ sonar.projectKey=fh-mbaas-api sonar.projectName=fh-mbaas-api-nightly-master -sonar.projectVersion=5.13.8 +sonar.projectVersion=5.13.9 sonar.sources=./lib sonar.tests=./test