cloudcms-server 0.9.301 → 3.3.1-beta.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/.last_command +7 -0
  2. package/broadcast/providers/redis.js +32 -57
  3. package/clients/nrp.js +117 -0
  4. package/clients/redis.js +48 -0
  5. package/duster/helpers/sample/nyt.js +5 -7
  6. package/framework/controllers.js +0 -1
  7. package/index.js +23 -13
  8. package/insight/insight.js +6 -9
  9. package/locks/providers/redis.js +29 -58
  10. package/middleware/admin/admin.js +4 -4
  11. package/middleware/awareness/awareness.js +4 -1
  12. package/middleware/awareness/plugins/editorial.js +41 -66
  13. package/middleware/awareness/plugins/resources.js +74 -0
  14. package/middleware/awareness/providers/redis.js +263 -237
  15. package/middleware/cache/providers/redis.js +134 -92
  16. package/middleware/config/config.js +41 -2
  17. package/middleware/deployment/deployment.js +19 -27
  18. package/middleware/form/form.js +18 -33
  19. package/middleware/modules/modules.js +64 -11
  20. package/middleware/proxy/proxy.js +1 -2
  21. package/middleware/stores/engines/s3.js +0 -2
  22. package/middleware/stores/stores.js +50 -6
  23. package/middleware/themes/themes.js +49 -0
  24. package/middleware/virtual-config/virtual-config.js +35 -39
  25. package/notifications/notifications.js +75 -2
  26. package/package.json +18 -20
  27. package/server/index.js +105 -23
  28. package/server/standalone.js +2 -0
  29. package/util/auth.js +5 -9
  30. package/util/cloudcms.js +19 -34
  31. package/util/proxy-factory.js +20 -8
  32. package/util/redis.js +113 -0
  33. package/util/renditions.js +6 -12
  34. package/util/request.js +117 -0
  35. package/util/util.js +31 -40
  36. package/web/socket.io/socket.io.js +4240 -2
  37. package/web/cms/ice.js +0 -109
  38. package/web/cms/preview.js +0 -106
package/server/index.js CHANGED
@@ -16,10 +16,14 @@ var session = require('express-session');
16
16
  var cookieParser = require('cookie-parser');
17
17
  var flash = require("connect-flash");
18
18
 
19
+ const redis = require('redis');
20
+ const connectRedis = require('connect-redis');
21
+
19
22
  // we don't bind a single passport - instead, we get the constructor here by hand
20
23
  var Passport = require("passport").Passport;
21
24
 
22
25
  var util = require("../util/util");
26
+ var redisHelper = require("../util/redis");
23
27
 
24
28
  var launchPad = require("../launchpad/index");
25
29
  var cluster = require("cluster");
@@ -37,6 +41,8 @@ var duster = require("../duster/index");
37
41
 
38
42
  var coreHelpers = require("../duster/helpers/core/index");
39
43
 
44
+ var helmet = require("helmet");
45
+
40
46
  var toobusy = require("toobusy-js");
41
47
  toobusy.maxLag(500); // 500 ms lag in event queue, quite high but usable for now
42
48
  toobusy.interval(250);
@@ -110,6 +116,7 @@ var SETTINGS = {
110
116
  "web": "app",
111
117
  "content": "tmp",
112
118
  "templates": "app",
119
+ "themes": "app",
113
120
  "modules": "app"
114
121
  },
115
122
  "virtual": {
@@ -118,6 +125,7 @@ var SETTINGS = {
118
125
  "web": "tmp",
119
126
  "content": "tmp",
120
127
  "templates": "tmp",
128
+ "themes": "tmp",
121
129
  "modules": "tmp"
122
130
  },
123
131
  "oneteam": {
@@ -126,6 +134,7 @@ var SETTINGS = {
126
134
  "web": "app",
127
135
  "content": "hosts_fs",
128
136
  "templates": "app",
137
+ "themes": "app",
129
138
  "modules": "hosts_fs"
130
139
  },
131
140
  "net-development": {
@@ -134,6 +143,7 @@ var SETTINGS = {
134
143
  "web": "hosts_fs",
135
144
  "content": "hosts_fs",
136
145
  "templates": "hosts_fs",
146
+ "themes": "hosts_fs",
137
147
  "modules": "hosts_fs"
138
148
  },
139
149
  "net-production": {
@@ -142,6 +152,7 @@ var SETTINGS = {
142
152
  "web": "hosts_s3fs",
143
153
  "content": "hosts_s3fs",
144
154
  "templates": "hosts_s3fs",
155
+ "themes": "hosts_s3fs",
145
156
  "modules": "hosts_s3fs"
146
157
  },
147
158
  "net-development-s3": {
@@ -149,7 +160,8 @@ var SETTINGS = {
149
160
  "config": "hosts_s3",
150
161
  "web": "hosts_s3",
151
162
  "content": "hosts_s3",
152
- "templates": "hosts_s3"
163
+ "templates": "hosts_s3",
164
+ "themes": "hosts_s3"
153
165
  },
154
166
  "net-development-s3fs": {
155
167
  "root": "hosts_s3fs",
@@ -157,6 +169,7 @@ var SETTINGS = {
157
169
  "web": "hosts_s3fs",
158
170
  "content": "hosts_s3fs",
159
171
  "templates": "hosts_s3fs",
172
+ "themes": "hosts_s3fs",
160
173
  "modules": "hosts_s3fs"
161
174
  }
162
175
  },
@@ -308,12 +321,12 @@ var SETTINGS = {
308
321
  process.env.PORT = process.env.PORT || 2999;
309
322
 
310
323
  // allows for specification of alternative transports
311
- SETTINGS.socketTransports = [
312
- 'websocket',
313
- 'xhr-polling',
314
- 'jsonp-polling',
315
- 'polling'
316
- ];
324
+ // SETTINGS.socketTransports = [
325
+ // 'websocket',
326
+ // 'xhr-polling',
327
+ // 'jsonp-polling',
328
+ // 'polling'
329
+ // ];
317
330
 
318
331
  var exports = module.exports;
319
332
 
@@ -585,7 +598,50 @@ var startSlave = function(config, afterStartFn)
585
598
  if (!process.env.CLOUDCMS_STANDALONE_HOST) {
586
599
  process.env.CLOUDCMS_STANDALONE_HOST = "local";
587
600
  }
588
-
601
+
602
+ // auto-configuration for HTTPS
603
+ if (!process.configuration.https) {
604
+ process.configuration.https = {};
605
+ }
606
+ if (process.env.CLOUDCMS_HTTPS) {
607
+ process.configuration.https = JSON.parse(process.env.CLOUDCMS_HTTPS);
608
+ }
609
+ if (process.env.CLOUDCMS_HTTPS_KEY_FILEPATH) {
610
+ process.configuration.https.key = fs.readFileSync(process.env.CLOUDCMS_HTTPS_KEY_FILEPATH);
611
+ }
612
+ if (process.env.CLOUDCMS_HTTPS_CERT_FILEPATH) {
613
+ process.configuration.https.cert = fs.readFileSync(process.env.CLOUDCMS_HTTPS_CERT_FILEPATH);
614
+ }
615
+ if (process.env.CLOUDCMS_HTTPS_PFX_FILEPATH) {
616
+ process.configuration.https.pfx = fs.readFileSync(process.env.CLOUDCMS_HTTPS_PFX_FILEPATH);
617
+ }
618
+ if (process.env.CLOUDCMS_HTTPS_PASSPHRASE) {
619
+ process.configuration.https.passphrase = process.env.CLOUDCMS_HTTPS_PASSPHRASE;
620
+ }
621
+ if (process.env.CLOUDCMS_HTTPS_REQUEST_CERT === "true") {
622
+ process.configuration.https.requestCert = true;
623
+ }
624
+ if (process.env.CLOUDCMS_HTTPS_CA_FILEPATH) {
625
+ process.configuration.https.ca = [ fs.readFileSync(process.env.CLOUDCMS_HTTPS_CA_FILEPATH) ];
626
+ }
627
+
628
+ // if https config is empty, remove it
629
+ if (Object.keys(process.configuration.https).length === 0) {
630
+ delete process.configuration.https;
631
+ }
632
+
633
+ // auto configuration of session store
634
+ if (!process.configuration.session) {
635
+ process.configuration.session = {};
636
+ }
637
+ if (process.env.CLOUDCMS_SESSION_TYPE) {
638
+ process.configuration.session.enabled = true;
639
+ process.configuration.session.type = process.env.CLOUDCMS_SESSION_TYPE;
640
+ }
641
+ if (process.env.CLOUDCMS_SESSION_SECRET) {
642
+ process.configuration.session.secret = process.env.CLOUDCMS_SESSION_SECRET;
643
+ }
644
+
589
645
  // session store
590
646
  var initializedSession = null;
591
647
  if (process.configuration.session)
@@ -618,6 +674,23 @@ var startSlave = function(config, afterStartFn)
618
674
  var SessionFileStore = require('session-file-store')(session);
619
675
  sessionConfig.store = new SessionFileStore(options);
620
676
  }
677
+ else if (process.configuration.session.type === "redis")
678
+ {
679
+ (async function() {
680
+ var redisOptions = redisHelper.redisOptions();
681
+ redisHelper.createAndConnect(redisOptions, function(err, redisClient) {
682
+
683
+ if (err) {
684
+ console.error(err);
685
+ }
686
+ else
687
+ {
688
+ var RedisStore = connectRedis(session);
689
+ sessionConfig.store = new RedisStore({ client: redisClient });
690
+ }
691
+ });
692
+ })();
693
+ }
621
694
  else if (process.configuration.session.type === "memory" || !process.configuration.session.type)
622
695
  {
623
696
  var options = {};
@@ -1043,25 +1116,34 @@ var startSlave = function(config, afterStartFn)
1043
1116
  // INITIALIZE THE SERVER
1044
1117
  //
1045
1118
  ////////////////////////////////////////////////////////////////////////////
1046
-
1047
-
1048
- // CORE OBJECTS
1049
- var server = http.Server(app);
1050
-
1119
+
1120
+ // create the server (either HTTP or HTTPS)
1121
+ var httpServer = null;
1122
+ if (process.configuration.https) {
1123
+ // configure helmet to support auto-upgrade of http->https
1124
+ app.use(helmet());
1125
+ // create https server
1126
+ httpServer = https.createServer(process.configuration.https, app);
1127
+ } else {
1128
+ // legacy
1129
+ httpServer = http.Server(app);
1130
+ }
1131
+
1051
1132
  // request timeout
1052
1133
  var requestTimeout = 30000; // 30 seconds
1053
1134
  if (process.configuration && process.configuration.timeout)
1054
1135
  {
1055
1136
  requestTimeout = process.configuration.timeout;
1056
1137
  }
1057
- server.setTimeout(requestTimeout);
1058
-
1138
+ httpServer.setTimeout(requestTimeout);
1139
+
1059
1140
  // socket
1060
- server.on("connection", function (socket) {
1141
+ httpServer.on("connection", function (socket) {
1061
1142
  socket.setNoDelay(true);
1062
1143
  });
1063
- var io = process.IO = require("socket.io")(server);
1064
- io.set('transports', config.socketTransports);
1144
+ const { Server } = require("socket.io");
1145
+ var io = process.IO = new Server(httpServer);
1146
+ //io.set('transports', config.socketTransports);
1065
1147
  io.use(function (socket, next) {
1066
1148
 
1067
1149
  // console.log("New socket being initialized");
@@ -1152,8 +1234,8 @@ var startSlave = function(config, afterStartFn)
1152
1234
 
1153
1235
  // APPLY SERVER BEFORE START FUNCTIONS
1154
1236
  runFunctions(config.beforeFunctions, [app], function (err) {
1155
-
1156
- server._listenPort = app.get("port");
1237
+
1238
+ httpServer._listenPort = app.get("port");
1157
1239
 
1158
1240
  // AFTER SERVER START
1159
1241
  runFunctions(config.afterFunctions, [app], function (err) {
@@ -1173,7 +1255,7 @@ var startSlave = function(config, afterStartFn)
1173
1255
 
1174
1256
  try
1175
1257
  {
1176
- server.close();
1258
+ httpServer.close();
1177
1259
  }
1178
1260
  catch (e)
1179
1261
  {
@@ -1213,8 +1295,8 @@ var startSlave = function(config, afterStartFn)
1213
1295
  {
1214
1296
  process.send("server-startup");
1215
1297
  }
1216
-
1217
- afterStartFn(app, server);
1298
+
1299
+ afterStartFn(app, httpServer);
1218
1300
 
1219
1301
  });
1220
1302
  });
@@ -46,6 +46,7 @@ server.report(function(callback) {
46
46
  console.log("Gitana Scheme: " + process.env.GITANA_PROXY_SCHEME);
47
47
  console.log("Gitana Host: " + process.env.GITANA_PROXY_HOST);
48
48
  console.log("Gitana Port: " + process.env.GITANA_PROXY_PORT);
49
+ console.log("Gitana Path: " + process.env.GITANA_PROXY_PATH);
49
50
  console.log("CPU Count: " + cpuCount);
50
51
 
51
52
  var virtualHost = null;
@@ -68,6 +69,7 @@ server.report(function(callback) {
68
69
  console.log("Hosts Directory: " + process.env.CLOUDCMS_HOSTS_PATH);
69
70
  console.log("LaunchPad Mode: " + process.env.CLOUDCMS_LAUNCHPAD_SETUP);
70
71
  console.log("Max Files Detected: " + process.env.CLOUDCMS_MAX_FILES);
72
+ console.log("Session Type: " + process.configuration.session.type);
71
73
 
72
74
  console.log("");
73
75
 
package/util/auth.js CHANGED
@@ -3,19 +3,21 @@ var fs = require('fs');
3
3
  var os = require('os');
4
4
  var _util = require("util");
5
5
  var util = require("./util");
6
- var request = require("request");
7
6
  var http = require("http");
8
7
  var https = require("https");
9
8
  var async = require("async");
9
+ var LRUCache = require("lru-cache");
10
+
11
+ var request = require("./request");
10
12
 
11
13
  // trusted profile cache size 100
12
- var TRUSTED_PROFILE_CACHE = require("lru-cache")({
14
+ var TRUSTED_PROFILE_CACHE = new LRUCache({
13
15
  max:100,
14
16
  maxAge: 1000 * 60 * 15 // 15 minutes
15
17
  });
16
18
 
17
19
  // user entry cache size 100
18
- var USER_ENTRY_CACHE = require("lru-cache")({
20
+ var USER_ENTRY_CACHE = new LRUCache({
19
21
  max: 100,
20
22
  maxAge: 1000 * 60 * 15 // 15 minutes
21
23
  });
@@ -137,15 +139,12 @@ var impersonate = exports.impersonate = function(req, key, targetUser, callback)
137
139
  var headers = {};
138
140
  headers["Authorization"] = req.gitana.platform().getDriver().getHttpHeaders()["Authorization"];
139
141
 
140
- var agent = util.getAgent(req.gitanaConfig.baseURL);
141
-
142
142
  request({
143
143
  "method": "POST",
144
144
  "url": req.gitanaConfig.baseURL + "/auth/impersonate/" + targetUser.getDomainId() + "/" + targetUser.getId(),
145
145
  "qs": {},
146
146
  "json": {},
147
147
  "headers": headers,
148
- "agent": agent,
149
148
  "timeout": process.defaultHttpTimeoutMs
150
149
  }, function(err, response, json) {
151
150
 
@@ -440,8 +439,6 @@ var __handleSyncUser = function(req, strategy, settings, key, domainId, provider
440
439
  var headers = {};
441
440
  headers["Authorization"] = authorizationHeader;
442
441
 
443
- var agent = util.getAgent(req.gitanaConfig.baseURL);
444
-
445
442
  if (!userObject) {
446
443
  userObject = {};
447
444
  }
@@ -467,7 +464,6 @@ var __handleSyncUser = function(req, strategy, settings, key, domainId, provider
467
464
  },
468
465
  "json": json,
469
466
  "headers": headers,
470
- "agent": agent,
471
467
  "timeout": process.defaultHttpTimeoutMs
472
468
  };
473
469
 
package/util/cloudcms.js CHANGED
@@ -1,11 +1,12 @@
1
1
  var path = require('path');
2
2
  var fs = require('fs');
3
3
  var util = require("./util");
4
- var request = require("request");
5
4
 
6
5
  var http = require("http");
7
6
  var https = require("https");
8
7
 
8
+ var request = require("./request");
9
+
9
10
  exports = module.exports = function()
10
11
  {
11
12
  var toCacheFilePath = function(filePath)
@@ -346,12 +347,10 @@ exports = module.exports = function()
346
347
  {
347
348
  if (attemptCount === maxAttemptsAllowed)
348
349
  {
349
- cb({
350
+ return cb({
350
351
  "message": "Maximum number of connection attempts exceeded(" + maxAttemptsAllowed + ")",
351
352
  "err": previousError
352
353
  });
353
-
354
- return;
355
354
  }
356
355
 
357
356
  contentStore.writeStream(filePath, function(err, tempStream) {
@@ -375,28 +374,24 @@ exports = module.exports = function()
375
374
  // add "authorization" for OAuth2 bearer token
376
375
  var headers2 = gitana.platform().getDriver().getHttpHeaders();
377
376
  headers["Authorization"] = headers2["Authorization"];
378
-
379
- var agent = http.globalAgent;
380
- if (process.env.GITANA_PROXY_SCHEME === "https")
381
- {
382
- agent = https.globalAgent;
383
- }
384
-
385
- var URL = util.asURL(process.env.GITANA_PROXY_SCHEME, process.env.GITANA_PROXY_HOST, process.env.GITANA_PROXY_PORT) + uri;
377
+
378
+ var URL = util.asURL(process.env.GITANA_PROXY_SCHEME, process.env.GITANA_PROXY_HOST, process.env.GITANA_PROXY_PORT, process.env.GITANA_PROXY_PATH) + uri;
386
379
  request({
387
380
  "method": "GET",
388
381
  "url": URL,
389
382
  "qs": {},
390
383
  "headers": headers,
391
- "timeout": process.defaultHttpTimeoutMs,
392
- "agent": agent
393
- }).on('response', function (response) {
384
+ "responseType": "stream"
385
+ }, function(err, response) {
394
386
 
395
- //process.log("Status Code: " + response.statusCode);
387
+ if (err) {
388
+ closeWriteStream(tempStream);
389
+ return cb(err);
390
+ }
396
391
 
397
- if (response.statusCode >= 200 && response.statusCode <= 204)
392
+ if (response.status >= 200 && response.status <= 204)
398
393
  {
399
- response.pipe(tempStream).on("close", function (err) {
394
+ response.data.pipe(tempStream).on("close", function (err) {
400
395
 
401
396
  // TODO: not needed here?
402
397
  // ensure stream is closed
@@ -463,6 +458,8 @@ exports = module.exports = function()
463
458
 
464
459
  }).on("error", function (err) {
465
460
 
461
+ console.log("f2");
462
+
466
463
  // ensure stream is closed
467
464
  closeWriteStream(tempStream);
468
465
 
@@ -475,7 +472,7 @@ exports = module.exports = function()
475
472
 
476
473
  var body = "";
477
474
 
478
- response.on('data', function (chunk) {
475
+ response.data.on('data', function (chunk) {
479
476
  body += chunk;
480
477
  });
481
478
 
@@ -507,7 +504,7 @@ exports = module.exports = function()
507
504
  // fire for retry
508
505
  return _refreshAccessTokenAndRetry(contentStore, gitana, uri, filePath, attemptCount, maxAttemptsAllowed, {
509
506
  "message": "Unable to load asset from remote store",
510
- "code": response.statusCode,
507
+ "code": response.status,
511
508
  "body": body
512
509
  }, cb);
513
510
  }
@@ -515,7 +512,7 @@ exports = module.exports = function()
515
512
  // otherwise, it's not worth retrying at this time
516
513
  cb({
517
514
  "message": "Unable to load asset from remote store",
518
- "code": response.statusCode,
515
+ "code": response.status,
519
516
  "body": body
520
517
  });
521
518
 
@@ -531,19 +528,7 @@ exports = module.exports = function()
531
528
 
532
529
  }
533
530
 
534
- }).on('error', function (e) {
535
-
536
- // ensure stream is closed
537
- closeWriteStream(tempStream);
538
-
539
- process.log("_writeToDisk request timed out");
540
- process.log(e)
541
- }).on('end', function (e) {
542
-
543
- // ensure stream is closed
544
- closeWriteStream(tempStream);
545
-
546
- }).end();
531
+ });
547
532
 
548
533
  tempStream.on("error", function (e) {
549
534
  process.log("Temp stream errored out");
@@ -11,6 +11,8 @@ var oauth2 = require("./oauth2")();
11
11
 
12
12
  var urlTool = require("url");
13
13
 
14
+ var LRUCache = require("lru-cache");
15
+
14
16
  var exports = module.exports;
15
17
 
16
18
  var _LOCK = function(lockIdentifiers, workFunction)
@@ -18,7 +20,7 @@ var _LOCK = function(lockIdentifiers, workFunction)
18
20
  process.locks.lock(lockIdentifiers.join("_"), workFunction);
19
21
  };
20
22
 
21
- var NAMED_PROXY_HANDLERS_CACHE = require("lru-cache")({
23
+ var NAMED_PROXY_HANDLERS_CACHE = new LRUCache({
22
24
  max: 200,
23
25
  maxAge: 1000 * 60 * 60 // 60 minutes
24
26
  });
@@ -97,15 +99,25 @@ var createProxyHandler = function(proxyTarget, pathPrefix)
97
99
 
98
100
  // create proxy server instance
99
101
  var proxyServer = new httpProxy.createProxyServer(proxyConfig);
100
-
102
+
101
103
  // error handling
102
104
  proxyServer.on("error", function(err, req, res) {
103
- process.log(err);
104
- res.writeHead(500, {
105
- 'Content-Type': 'text/plain'
106
- });
107
-
108
- res.end('Something went wrong while proxying the request.');
105
+ console.log("A proxy error was caught: " + err + ", json: " + JSON.stringify(err) + ", path: " + req.path);
106
+
107
+ // do our best to send something back
108
+ try
109
+ {
110
+ res.writeHead(500, {
111
+ 'Content-Type': 'text/plain'
112
+ });
113
+ }
114
+ catch (e) { }
115
+
116
+ try
117
+ {
118
+ res.end('Something went wrong while proxying the request.');
119
+ }
120
+ catch (e) { }
109
121
  });
110
122
 
111
123
  // if we're using auth credentials that are picked up in SSO chain, then we listen for a 401
package/util/redis.js ADDED
@@ -0,0 +1,113 @@
1
+ var redis = require("redis");
2
+ const logFactory = require("./logger");
3
+
4
+ exports = module.exports;
5
+
6
+ var redisLogger = exports.redisLogger = function(name, prefix, defaultLevel)
7
+ {
8
+ if (!defaultLevel) {
9
+ defaultLevel = "error";
10
+ }
11
+
12
+ var level = null;
13
+
14
+ // allow for global redis default
15
+ // allow for prefix specific
16
+ if (typeof(process.env["CLOUDCMS_REDIS_DEBUG_LEVEL"]) !== "undefined") {
17
+ level = "" + process.env["CLOUDCMS_REDIS_DEBUG_LEVEL"].toLowerCase();
18
+ }
19
+
20
+ if (!level && prefix)
21
+ {
22
+ if (typeof(process.env[prefix + "REDIS_DEBUG_LEVEL"]) !== "undefined") {
23
+ level = "" + process.env[prefix + "REDIS_DEBUG_LEVEL"].toLowerCase();
24
+ }
25
+ }
26
+
27
+ if (!level) {
28
+ level = defaultLevel;
29
+ }
30
+
31
+ var logger = logFactory(name);
32
+ logger.setLevel(level);
33
+
34
+ return logger;
35
+ }
36
+
37
+ var redisOptions = exports.redisOptions = function(config, prefix)
38
+ {
39
+ if (!config) {
40
+ config = {};
41
+ }
42
+
43
+ // redis port
44
+ var redisPort = config.port;
45
+ if (prefix)
46
+ {
47
+ if (typeof(redisPort) === "undefined" || !redisPort)
48
+ {
49
+ // CLOUDCMS_LOCKS_REDIS_PORT;
50
+ redisPort = process.env[prefix + "_REDIS_PORT"];
51
+ }
52
+ }
53
+ if (typeof(redisPort) === "undefined" || !redisPort)
54
+ {
55
+ redisPort = process.env.CLOUDCMS_REDIS_PORT;
56
+ }
57
+
58
+ // redis host
59
+ var redisEndpoint = config.endpoint;
60
+ if (prefix)
61
+ {
62
+ if (typeof(redisEndpoint) === "undefined" || !redisEndpoint)
63
+ {
64
+ redisEndpoint = process.env[prefix + "_REDIS_ENDPOINT"];
65
+ }
66
+ }
67
+ if (typeof(redisEndpoint) === "undefined" || !redisEndpoint)
68
+ {
69
+ redisEndpoint = process.env.CLOUDCMS_REDIS_ENDPOINT;
70
+ }
71
+
72
+ // redis url
73
+ var redisUrl = config.url;
74
+ if (prefix)
75
+ {
76
+ if (typeof(redisUrl) === "undefined" || !redisUrl)
77
+ {
78
+ redisUrl = process.env[prefix + "_REDIS_URL"];
79
+ }
80
+ }
81
+ if (typeof(redisUrl) === "undefined" || !redisUrl)
82
+ {
83
+ redisUrl = process.env.CLOUDCMS_REDIS_URL;
84
+ }
85
+
86
+ // build redis URL from components if not otherwise provided
87
+ if (!redisUrl)
88
+ {
89
+ redisUrl = "redis://" + redisEndpoint + ":" + redisPort;
90
+ }
91
+
92
+ var redisOptions = {};
93
+ redisOptions.url = redisUrl;
94
+
95
+ return redisOptions;
96
+ }
97
+
98
+ var createAndConnect = exports.createAndConnect = async function(redisOptions, callback)
99
+ {
100
+ var client = redis.createClient(redisOptions);
101
+
102
+ var connectErr = null;
103
+ client.on('error', function(err) {
104
+ console.log('Redis Client Error', err);
105
+ connectErr = err;
106
+ });
107
+
108
+ // connect
109
+ await client.connect();
110
+ //console.log("Connected to redis, options: " + JSON.stringify(redisOptions, null, 2) + ", err: " + connectErr + ", client: " + client);
111
+
112
+ return callback(connectErr, client);
113
+ }
@@ -2,12 +2,13 @@ var path = require('path');
2
2
  var fs = require('fs');
3
3
  var util = require("../util/util");
4
4
  var async = require("async");
5
- var request = require("request");
6
5
 
7
6
  var http = require("http");
8
7
  var https = require("https");
9
8
 
10
- var logFactory = require("../util/logger");
9
+ var logFactory = require("./logger");
10
+
11
+ var request = require("./request");
11
12
 
12
13
  /**
13
14
  * WCM Resource Dependency Manager
@@ -61,13 +62,7 @@ exports = module.exports = function()
61
62
 
62
63
  var syncRows = function(rows, callback)
63
64
  {
64
- var URL = util.asURL(process.env.GITANA_PROXY_SCHEME, process.env.GITANA_PROXY_HOST, process.env.GITANA_PROXY_PORT) + "/bulk/pagerenditions";
65
-
66
- var agent = http.globalAgent;
67
- if (process.env.GITANA_PROXY_SCHEME === "https")
68
- {
69
- agent = https.globalAgent;
70
- }
65
+ var URL = util.asURL(process.env.GITANA_PROXY_SCHEME, process.env.GITANA_PROXY_HOST, process.env.GITANA_PROXY_PORT, process.env.GITANA_PROXY_PATH) + "/bulk/pagerenditions";
71
66
 
72
67
  // add "authorization" for OAuth2 bearer token
73
68
  var headers = {};
@@ -82,9 +77,8 @@ exports = module.exports = function()
82
77
  "rows": rows
83
78
  },
84
79
  "headers": headers,
85
- "timeout": process.defaultHttpTimeoutMs,
86
- "agent": agent
87
- }, function (err, response, body) {
80
+ "timeout": process.defaultHttpTimeoutMs
81
+ }, function (err, response, json) {
88
82
  callback();
89
83
  });
90
84
  };