cloudcms-server 3.3.1-beta.9 → 4.0.0-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 (119) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1 -1
  3. package/broadcast/broadcast.js +6 -3
  4. package/broadcast/providers/redis.js +24 -49
  5. package/clients/nrp.js +117 -0
  6. package/clients/redis.js +64 -0
  7. package/cloudcms-server.iml +1 -0
  8. package/d1/index.js +629 -0
  9. package/d1/index.js.works +203 -0
  10. package/d1/package.json +86 -0
  11. package/d1/package.json.works +14 -0
  12. package/duster/helpers/sample/nyt.js +2 -1
  13. package/framework/controllers.js +4 -4
  14. package/index.js +21 -14
  15. package/insight/insight.js +1 -1
  16. package/launchpad/index.js +203 -11
  17. package/launchpad/launchers/cluster.js +103 -110
  18. package/launchpad/launchers/redis.js +70 -0
  19. package/launchpad/launchers/single.js +36 -22
  20. package/locks/locks.js +63 -9
  21. package/locks/providers/cluster.js +3 -1
  22. package/locks/providers/memory.js +10 -7
  23. package/locks/providers/redis.js +62 -82
  24. package/middleware/admin/admin.js +3 -3
  25. package/middleware/authentication/adapters/session.js +11 -8
  26. package/middleware/authentication/authentication.js +28 -16
  27. package/middleware/authentication/authenticators/default.js +5 -2
  28. package/middleware/authentication/authenticators/session.js +5 -2
  29. package/middleware/authentication/providers/saml.js +2 -2
  30. package/middleware/authorization/authorization.js +11 -8
  31. package/middleware/awareness/awareness.js +63 -38
  32. package/middleware/awareness/plugins/api_event.js +105 -0
  33. package/middleware/awareness/plugins/editorial.js +8 -7
  34. package/middleware/awareness/plugins/resources.js +13 -5
  35. package/middleware/awareness/providers/abstract-async.js +107 -84
  36. package/middleware/awareness/providers/abstract.js +1 -1
  37. package/middleware/awareness/providers/memory.js +0 -14
  38. package/middleware/awareness/providers/redis.js +186 -279
  39. package/middleware/cache/cache.js +4 -2
  40. package/middleware/cache/providers/redis.js +127 -89
  41. package/middleware/cache/providers/shared-memory.js +3 -3
  42. package/middleware/cloudcms/cloudcms.js +22 -16
  43. package/middleware/driver-config/driver-config.js +0 -6
  44. package/middleware/form/form.js +3 -3
  45. package/middleware/modules/modules.js +17 -8
  46. package/middleware/perf/perf.js +3 -2
  47. package/middleware/proxy/proxy.js +8 -21
  48. package/middleware/stores/store.js +0 -1
  49. package/middleware/stores/stores.js +4 -4
  50. package/middleware/virtual-config/virtual-config.js +11 -11
  51. package/middleware/virtual-files/virtual-files.js +0 -3
  52. package/middleware/wcm/wcm.js +4 -4
  53. package/middleware/welcome/welcome.js +0 -3
  54. package/notifications/notifications.js +74 -12
  55. package/notifications/providers/kafka.js +182 -0
  56. package/notifications/providers/stomp.js +4 -0
  57. package/package.json +33 -30
  58. package/server/index.js +508 -416
  59. package/server/standalone.js +9 -0
  60. package/temp/clusterlock/index.js +3 -3
  61. package/temp/clusterlock/package.json +1 -1
  62. package/temp/passport-saml/LICENSE +23 -0
  63. package/temp/passport-saml/README.md +406 -0
  64. package/temp/passport-saml/lib/node-saml/algorithms.d.ts +5 -0
  65. package/temp/passport-saml/lib/node-saml/algorithms.js +41 -0
  66. package/temp/passport-saml/lib/node-saml/algorithms.js.map +1 -0
  67. package/temp/passport-saml/lib/node-saml/index.d.ts +3 -0
  68. package/temp/passport-saml/lib/node-saml/index.js +6 -0
  69. package/temp/passport-saml/lib/node-saml/index.js.map +1 -0
  70. package/temp/passport-saml/lib/node-saml/inmemory-cache-provider.d.ts +45 -0
  71. package/temp/passport-saml/lib/node-saml/inmemory-cache-provider.js +86 -0
  72. package/temp/passport-saml/lib/node-saml/inmemory-cache-provider.js.map +1 -0
  73. package/temp/passport-saml/lib/node-saml/saml-post-signing.d.ts +3 -0
  74. package/temp/passport-saml/lib/node-saml/saml-post-signing.js +15 -0
  75. package/temp/passport-saml/lib/node-saml/saml-post-signing.js.map +1 -0
  76. package/temp/passport-saml/lib/node-saml/saml.d.ts +77 -0
  77. package/temp/passport-saml/lib/node-saml/saml.js +1170 -0
  78. package/temp/passport-saml/lib/node-saml/saml.js.map +1 -0
  79. package/temp/passport-saml/lib/node-saml/types.d.ts +95 -0
  80. package/temp/passport-saml/lib/node-saml/types.js +8 -0
  81. package/temp/passport-saml/lib/node-saml/types.js.map +1 -0
  82. package/temp/passport-saml/lib/node-saml/utility.d.ts +3 -0
  83. package/temp/passport-saml/lib/node-saml/utility.js +19 -0
  84. package/temp/passport-saml/lib/node-saml/utility.js.map +1 -0
  85. package/temp/passport-saml/lib/node-saml/xml.d.ts +21 -0
  86. package/temp/passport-saml/lib/node-saml/xml.js +140 -0
  87. package/temp/passport-saml/lib/node-saml/xml.js.map +1 -0
  88. package/temp/passport-saml/lib/passport-saml/index.d.ts +6 -0
  89. package/temp/passport-saml/lib/passport-saml/index.js +11 -0
  90. package/temp/passport-saml/lib/passport-saml/index.js.map +1 -0
  91. package/temp/passport-saml/lib/passport-saml/multiSamlStrategy.d.ts +13 -0
  92. package/temp/passport-saml/lib/passport-saml/multiSamlStrategy.js +63 -0
  93. package/temp/passport-saml/lib/passport-saml/multiSamlStrategy.js.map +1 -0
  94. package/temp/passport-saml/lib/passport-saml/strategy.d.ts +20 -0
  95. package/temp/passport-saml/lib/passport-saml/strategy.js +167 -0
  96. package/temp/passport-saml/lib/passport-saml/strategy.js.map +1 -0
  97. package/temp/passport-saml/lib/passport-saml/types.d.ts +51 -0
  98. package/temp/passport-saml/lib/passport-saml/types.js +11 -0
  99. package/temp/passport-saml/lib/passport-saml/types.js.map +1 -0
  100. package/temp/passport-saml/package.json +96 -0
  101. package/util/auth.js +16 -10
  102. package/util/cloudcms.js +108 -120
  103. package/util/proxy-factory.js +103 -237
  104. package/util/redis.js +113 -0
  105. package/util/renditions.js +12 -6
  106. package/util/request.js +12 -6
  107. package/util/util.js +16 -2
  108. package/.last_command +0 -7
  109. package/launchpad/launchers/sticky-cluster.js +0 -43
  110. package/temp/memored/.jshintrc +0 -4
  111. package/temp/memored/README.md +0 -240
  112. package/temp/memored/demo/demo1.js +0 -37
  113. package/temp/memored/demo/demo2.js +0 -32
  114. package/temp/memored/gulpfile.js +0 -8
  115. package/temp/memored/index.js +0 -343
  116. package/temp/memored/package.json +0 -54
  117. package/temp/memored/spec/memored.spec.js +0 -265
  118. package/web/cms/ice.js +0 -109
  119. package/web/cms/preview.js +0 -106
@@ -1,28 +1,25 @@
1
- var http = require("http");
2
- var https = require("https");
1
+ // var http = require("http");
2
+ // var https = require("https");
3
3
  var path = require("path");
4
4
 
5
- var httpProxy = require("http-proxy");
6
-
7
5
  var auth = require("./auth");
8
- var util = require("./util");
6
+ // var util = require("./util");
9
7
 
10
8
  var oauth2 = require("./oauth2")();
11
9
 
12
- var urlTool = require("url");
13
-
14
- var LRUCache = require("lru-cache");
10
+ var LRU = require("lru-cache");
15
11
 
16
12
  var exports = module.exports;
17
13
 
18
14
  var _LOCK = function(lockIdentifiers, workFunction)
19
15
  {
20
- process.locks.lock(lockIdentifiers.join("_"), workFunction);
16
+ var name = lockIdentifiers.join("_");
17
+ process.locks.lock(name, workFunction);
21
18
  };
22
19
 
23
- var NAMED_PROXY_HANDLERS_CACHE = new LRUCache({
20
+ var NAMED_PROXY_HANDLERS_CACHE = new LRU({
24
21
  max: 200,
25
- maxAge: 1000 * 60 * 60 // 60 minutes
22
+ ttl: 1000 * 60 * 60 // 60 minutes
26
23
  });
27
24
 
28
25
  var acquireProxyHandler = exports.acquireProxyHandler = function(proxyTarget, pathPrefix, callback)
@@ -37,113 +34,86 @@ var acquireProxyHandler = exports.acquireProxyHandler = function(proxyTarget, pa
37
34
  return callback(null, _cachedHandler);
38
35
  }
39
36
 
40
- // take out a thread lock
41
- _LOCK(["acquireProxyHandler", name], function(releaseLockFn) {
42
-
43
- // second check to make sure another thread didn't create the handler in the meantime
44
- _cachedHandler = NAMED_PROXY_HANDLERS_CACHE[name];
45
- if (_cachedHandler)
46
- {
47
- releaseLockFn();
48
- return callback(null, _cachedHandler);
49
- }
50
-
51
- // create the proxy handler and cache it into LRU cache
52
- _cachedHandler = createProxyHandler(proxyTarget, pathPrefix);
53
-
54
- // store back into LRU cache
55
- NAMED_PROXY_HANDLERS_CACHE[name] = _cachedHandler;
56
-
57
- releaseLockFn();
58
- callback(null, _cachedHandler);
59
- });
60
- };
61
-
62
- var createProxyHandler = function(proxyTarget, pathPrefix)
63
- {
64
- ////////////////////////////////////////////////////////////////////////////
37
+ // // take out a thread lock
38
+ // _LOCK(["acquireProxyHandler", name], function(err, releaseLockFn) {
65
39
  //
66
- // HTTP/HTTPS Proxy Server to Cloud CMS
67
- // Facilitates Cross-Domain communication between Browser and Cloud Server
68
- // This must appear at the top of the app.js file (ahead of config) for things to work
40
+ // if (err)
41
+ // {
42
+ // console.log("Failed to acquire proxy handler: " + name + ", err: ", err);
69
43
  //
70
- ////////////////////////////////////////////////////////////////////////////
71
-
72
- // NOTE: changeOrigin must be true because of the way that we set host to host:port
73
- // in http-proxy's common.js line 102, the host is only properly set up if changeOrigin is set to true
74
- // this sets the "host" header and it has to match what is set at the network/transport level in a way
75
- // (inner workings of Node http request)
44
+ // // failed to acquire lock
45
+ // return callback(err);
46
+ // }
76
47
  //
77
- var proxyConfig = {
78
- "target": proxyTarget,
79
- "agent": http.globalAgent,
80
- "xfwd": false,
81
- "proxyTimeout": process.defaultHttpTimeoutMs,
82
- "changeOrigin": true
83
- };
48
+ // // second check to make sure another thread didn't create the handler in the meantime
49
+ // _cachedHandler = NAMED_PROXY_HANDLERS_CACHE[name];
50
+ // if (_cachedHandler)
51
+ // {
52
+ // releaseLockFn();
53
+ // return callback(null, _cachedHandler);
54
+ // }
55
+ //
56
+ // // create the proxy handler and cache it into LRU cache
57
+ // //console.log("Acquiring proxy handler: " + name + ", for target: " + proxyTarget + " and prefix: " + pathPrefix);
58
+ // _cachedHandler = createProxyHandler(proxyTarget, pathPrefix);
59
+ //
60
+ // // store back into LRU cache
61
+ // NAMED_PROXY_HANDLERS_CACHE[name] = _cachedHandler;
62
+ //
63
+ // releaseLockFn();
64
+ // callback(null, _cachedHandler);
65
+ // });
84
66
 
85
- // use https?
86
- if (util.isHttps(proxyTarget))
87
- {
88
- // parse the target to get host
89
- var proxyHost = urlTool.parse(proxyTarget).host;
90
-
91
- proxyConfig = {
92
- "target": proxyTarget,
93
- "agent": https.globalAgent,
94
- "headers": {
95
- "host": proxyHost
96
- }
97
- };
98
- }
67
+ _cachedHandler = NAMED_PROXY_HANDLERS_CACHE[name] = createProxyHandler(proxyTarget, pathPrefix);
99
68
 
100
- // create proxy server instance
101
- var proxyServer = new httpProxy.createProxyServer(proxyConfig);
69
+ callback(null, _cachedHandler);
70
+ };
102
71
 
103
- // error handling
104
- proxyServer.on("error", function(err, req, res) {
105
- console.log("A proxy error was caught: " + err + ", json: " + JSON.stringify(err));
106
72
 
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
73
 
116
- try
117
- {
118
- res.end('Something went wrong while proxying the request.');
119
- }
120
- catch (e) { }
74
+
75
+ var createProxyHandler = function(proxyTarget, pathPrefix)
76
+ {
77
+ const { proxy, close } = require('fast-proxy')({
78
+ base: proxyTarget,
79
+ cacheURLs: 0,
80
+ //http2: true,
81
+ //undici: true
121
82
  });
122
83
 
123
- // if we're using auth credentials that are picked up in SSO chain, then we listen for a 401
124
- // and if we hear it, we automatically invalidate the SSO chain so that the next request
125
- // will continue to work
126
- proxyServer.on("proxyRes", function (proxyRes, req, res) {
84
+ var proxyOptions = {};
85
+ proxyOptions.onResponse = function(req, res, stream) {
127
86
 
128
87
  if (req.gitana_user)
129
88
  {
130
89
  var chunks = [];
90
+
131
91
  // triggers on data receive
132
- proxyRes.on('data', function(chunk) {
92
+ stream.on('data', function(chunk) {
93
+ console.log("DATA!");
133
94
  // add received chunk to chunks array
134
95
  chunks.push(chunk);
135
96
  });
136
97
 
137
- proxyRes.on("end", function () {
98
+ stream.on("end", function () {
138
99
 
139
- if (proxyRes.statusCode === 401)
100
+ if (stream.statusCode === 401)
140
101
  {
141
102
  var text = "" + Buffer.concat(chunks);
142
103
  if (text && (text.indexOf("invalid_token") > -1) || (text.indexOf("invalid_grant") > -1))
143
104
  {
144
105
  var identifier = req.identity_properties.provider_id + "/" + req.identity_properties.user_identifier;
145
106
 
146
- _LOCK([identifier], function(releaseLockFn) {
107
+ _LOCK([identifier], function(err, releaseLockFn) {
108
+
109
+ if (err)
110
+ {
111
+ // failed to acquire lock
112
+ console.log("FAILED TO ACQUIRE LOCK", err);
113
+ req.log("FAILED TO ACQUIRE LOCK", err);
114
+ try { releaseLockFn(); } catch (e) { }
115
+ return;
116
+ }
147
117
 
148
118
  var cleanup = function (full)
149
119
  {
@@ -162,8 +132,7 @@ var createProxyHandler = function(proxyTarget, pathPrefix)
162
132
  if (err) {
163
133
  cleanup(true);
164
134
  req.log("Invalidated auth state for gitana user: " + req.identity_properties.token);
165
- releaseLockFn();
166
- return;
135
+ return releaseLockFn();
167
136
  }
168
137
 
169
138
  req.gitana_user.getDriver().reloadAuthInfo(function () {
@@ -178,23 +147,31 @@ var createProxyHandler = function(proxyTarget, pathPrefix)
178
147
  }
179
148
  });
180
149
  }
181
- });
182
150
 
183
- var proxyHandlerServer = http.createServer(function(req, res) {
151
+ //res.setHeader('x-powered-by', 'cloudcms');
152
+ if (stream.statusCode && stream.headers) {
153
+ res.writeHead(stream.statusCode, stream.headers)
154
+ }
184
155
 
156
+ stream.pipe(res)
157
+ };
158
+ proxyOptions.rewriteRequestHeaders = function(req, headers)
159
+ {
185
160
  // used to auto-assign the client header for /oauth/token requests
186
161
  oauth2.autoProxy(req);
162
+ if (req.headers && req.headers.authorization)
163
+ {
164
+ headers["authorization"] = req.headers.authorization;
165
+ }
187
166
 
188
167
  // copy domain host into "x-cloudcms-domainhost"
189
- if (req.domainHost)
190
- {
191
- req.headers["x-cloudcms-domainhost"] = req.domainHost; // this could be "localhost"
168
+ if (req.domainHost) {
169
+ headers["x-cloudcms-domainhost"] = req.domainHost; // this could be "localhost"
192
170
  }
193
171
 
194
172
  // copy virtual host into "x-cloudcms-virtualhost"
195
- if (req.virtualHost)
196
- {
197
- req.headers["x-cloudcms-virtualhost"] = req.virtualHost; // this could be "root.cloudcms.net" or "abc.cloudcms.net"
173
+ if (req.virtualHost) {
174
+ headers["x-cloudcms-virtualhost"] = req.virtualHost; // this could be "root.cloudcms.net" or "abc.cloudcms.net"
198
175
  }
199
176
 
200
177
  // copy deployment descriptor info
@@ -204,12 +181,12 @@ var createProxyHandler = function(proxyTarget, pathPrefix)
204
181
  {
205
182
  if (req.descriptor.tenant.id)
206
183
  {
207
- req.headers["x-cloudcms-tenant-id"] = req.descriptor.tenant.id;
184
+ headers["x-cloudcms-tenant-id"] = req.descriptor.tenant.id;
208
185
  }
209
186
 
210
187
  if (req.descriptor.tenant.title)
211
188
  {
212
- req.headers["x-cloudcms-tenant-title"] = req.descriptor.tenant.title;
189
+ headers["x-cloudcms-tenant-title"] = req.descriptor.tenant.title;
213
190
  }
214
191
  }
215
192
 
@@ -217,12 +194,12 @@ var createProxyHandler = function(proxyTarget, pathPrefix)
217
194
  {
218
195
  if (req.descriptor.application.id)
219
196
  {
220
- req.headers["x-cloudcms-application-id"] = req.descriptor.application.id;
197
+ headers["x-cloudcms-application-id"] = req.descriptor.application.id;
221
198
  }
222
199
 
223
200
  if (req.descriptor.application.title)
224
201
  {
225
- req.headers["x-cloudcms-application-title"] = req.descriptor.application.title;
202
+ headers["x-cloudcms-application-title"] = req.descriptor.application.title;
226
203
  }
227
204
  }
228
205
  }
@@ -235,134 +212,14 @@ var createProxyHandler = function(proxyTarget, pathPrefix)
235
212
  }
236
213
  if (cloudcmsOrigin)
237
214
  {
238
- req.headers["x-cloudcms-origin"] = cloudcmsOrigin;
215
+ headers["x-cloudcms-origin"] = cloudcmsOrigin;
239
216
  }
240
217
 
241
218
  // set x-cloudcms-server-version header
242
- req.headers["x-cloudcms-server-version"] = process.env.CLOUDCMS_APPSERVER_PACKAGE_VERSION;
243
-
244
- // determine the domain to set the "host" header on the proxied call
245
- // this is what we pass to the API server
246
- var cookieDomain = req.domainHost;
247
-
248
- // if the incoming request is coming off of a CNAME entry that is maintained elsewhere (and they're just
249
- // forwarding the CNAME request to our machine), then we try to detect this...
250
- //
251
- // our algorithm here is pretty weak but suffices for the moment.
252
- // if the req.headers["x-forwarded-host"] first entry is in the req.headers["referer"] then we consider
253
- // things to have been CNAME forwarded
254
- // and so we write cookies back to the req.headers["x-forwarded-host"] first entry domain
255
- /*
256
- var xForwardedHost = req.headers["x-forwarded-host"];
257
- if (xForwardedHost)
258
- {
259
- xForwardedHost = xForwardedHost.split(",");
260
- if (xForwardedHost.length > 0)
261
- {
262
- var cnameCandidate = xForwardedHost[0];
263
-
264
- var referer = req.headers["referer"];
265
- if (referer && referer.indexOf("://" + cnameCandidate) > -1)
266
- {
267
- req.log("Detected CNAME: " + cnameCandidate);
268
-
269
- proxyHostHeader = cnameCandidate;
270
- }
271
- }
272
- }
273
- */
274
-
275
- // we fall back to using http-node-proxy's xfwd support
276
- // thus, spoof header here on request so that "x-forwarded-host" is set properly
277
- //req.headers["host"] = proxyHostHeader;
219
+ headers["x-cloudcms-server-version"] = process.env.CLOUDCMS_APPSERVER_PACKAGE_VERSION;
278
220
 
279
221
  // keep alive
280
- req.headers["connection"] = "keep-alive";
281
-
282
- // allow forced cookie domains
283
- var forcedCookieDomain = req.headers["cloudcmscookiedomain"];
284
- if (!forcedCookieDomain)
285
- {
286
- if (process.env.CLOUDCMS_FORCE_COOKIE_DOMAIN)
287
- {
288
- forcedCookieDomain = process.env.CLOUDCMS_FORCE_COOKIE_DOMAIN;
289
- }
290
- }
291
- if (forcedCookieDomain)
292
- {
293
- cookieDomain = forcedCookieDomain;
294
- }
295
-
296
- var updateSetCookieValue = function(value)
297
- {
298
- // replace the domain with the host
299
- var i = value.toLowerCase().indexOf("domain=");
300
- if (i > -1)
301
- {
302
- var j = value.indexOf(";", i);
303
- if (j === -1)
304
- {
305
- value = value.substring(0, i);
306
- }
307
- else
308
- {
309
- value = value.substring(0, i) + value.substring(j);
310
- }
311
- }
312
-
313
- // if the originating request isn't secure, strip out "secure" from cookie
314
- if (!util.isSecure(req))
315
- {
316
- var i = value.toLowerCase().indexOf("; secure");
317
- if (i > -1)
318
- {
319
- value = value.substring(0, i);
320
- }
321
- }
322
-
323
- // if the original request is secure, ensure cookies have "secure" set
324
- if (util.isSecure(req))
325
- {
326
- var i = value.toLowerCase().indexOf("; secure");
327
- var j = value.toLowerCase().indexOf(";secure");
328
- if (i === -1 && j === -1)
329
- {
330
- value += ";secure";
331
- }
332
- }
333
-
334
- return value;
335
- };
336
-
337
- // handles the setting of response headers
338
- // we filter off stuff we do not care about
339
- // we ensure proper domain on set-cookie (TODO: is this needed anymore?)
340
- var _setHeader = res.setHeader;
341
- res.setHeader = function(key, value)
342
- {
343
- var _key = key.toLowerCase();
344
-
345
- if (_key.indexOf("access-control-") === 0)
346
- {
347
- // skip any access control headers
348
- }
349
- else
350
- {
351
- if (_key === "set-cookie")
352
- {
353
- for (var x in value)
354
- {
355
- value[x] = updateSetCookieValue(value[x]);
356
- }
357
- }
358
-
359
- var existing = this.getHeader(key);
360
- if (!existing)
361
- {
362
- _setHeader.call(this, key, value);
363
- }
364
- }
365
- };
222
+ //req.headers["connection"] = "keep-alive";
366
223
 
367
224
  // if the incoming request didn't have an "Authorization" header
368
225
  // and we have a logged in Gitana User via Auth, then set authorization header to Bearer Access Token
@@ -370,20 +227,29 @@ var createProxyHandler = function(proxyTarget, pathPrefix)
370
227
  {
371
228
  if (req.gitana_user)
372
229
  {
373
- req.headers["authorization"] = "Bearer " + req.gitana_user.getDriver().http.accessToken();
230
+ headers["authorization"] = "Bearer " + req.gitana_user.getDriver().http.accessToken();
374
231
  }
375
232
  else if (req.gitana_proxy_access_token)
376
233
  {
377
- req.headers["authorization"] = "Bearer " + req.gitana_proxy_access_token;
234
+ headers["authorization"] = "Bearer " + req.gitana_proxy_access_token;
378
235
  }
379
236
  }
380
237
 
381
- if (pathPrefix) {
382
- req.url = path.join(pathPrefix, req.url);
383
- }
238
+ return headers;
239
+ };
240
+ // rewrite response headers
241
+ proxyOptions.rewriteHeaders = function(headers)
242
+ {
243
+ return headers;
244
+ };
245
+ // request invoke settings
246
+ //proxyOptions.request = {};
384
247
 
385
- proxyServer.web(req, res);
386
- });
248
+ //////////////////////////////////////////////////////////////////////////
249
+
250
+ var proxyRequestHandler = function(req, res) {
251
+ proxy(req, res, pathPrefix, proxyOptions);
252
+ };
387
253
 
388
- return proxyHandlerServer.listeners('request')[0];
254
+ return proxyRequestHandler;
389
255
  };
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
+ }
@@ -1,10 +1,10 @@
1
- var path = require('path');
2
- var fs = require('fs');
1
+ // var path = require('path');
2
+ // var fs = require('fs');
3
3
  var util = require("../util/util");
4
- var async = require("async");
4
+ //var async = require("async");
5
5
 
6
- var http = require("http");
7
- var https = require("https");
6
+ // var http = require("http");
7
+ // var https = require("https");
8
8
 
9
9
  var logFactory = require("./logger");
10
10
 
@@ -62,7 +62,13 @@ exports = module.exports = function()
62
62
 
63
63
  var syncRows = function(rows, callback)
64
64
  {
65
- var URL = util.asURL(process.env.GITANA_PROXY_SCHEME, process.env.GITANA_PROXY_HOST, process.env.GITANA_PROXY_PORT) + "/bulk/pagerenditions";
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";
66
+
67
+ var agent = http.globalAgent;
68
+ if (process.env.GITANA_PROXY_SCHEME === "https")
69
+ {
70
+ agent = https.globalAgent;
71
+ }
66
72
 
67
73
  // add "authorization" for OAuth2 bearer token
68
74
  var headers = {};
package/util/request.js CHANGED
@@ -1,9 +1,9 @@
1
1
  var axios = require("axios");
2
2
 
3
- var http = require("http");
4
- var https = require("https");
5
-
6
- var FormData = require("form-data");
3
+ // var http = require("http");
4
+ // var https = require("https");
5
+ //
6
+ // var FormData = require("form-data");
7
7
 
8
8
  /**
9
9
  * Incoming config:
@@ -28,7 +28,13 @@ module.exports = function(config, callback)
28
28
  {
29
29
  // request config - https://github.com/request/request#requestoptions-callback
30
30
  // axios config - https://www.npmjs.com/package/axios
31
-
31
+
32
+ if (!callback) {
33
+ callback = function(err, response, data) {
34
+ // nothing
35
+ };
36
+ }
37
+
32
38
  var requestConfig = {};
33
39
  requestConfig.url = config.uri || config.url;
34
40
  requestConfig.method = config.method || "get";
@@ -109,7 +115,7 @@ module.exports = function(config, callback)
109
115
  }
110
116
  */
111
117
 
112
- axios.request(requestConfig).then(function(response) {
118
+ return axios.request(requestConfig).then(function(response) {
113
119
  callback(null, response, response.data);
114
120
  }, function(error) {
115
121
  callback(error);
package/util/util.js CHANGED
@@ -603,7 +603,7 @@ var executeFunction = exports.executeFunction = function(identifier, fn, afterFn
603
603
  // take out a lock to ensure that the first thread to pass through here is the only one
604
604
  // and gets to run by itself on the cluster
605
605
  var exclusiveLockKey = "exclusiveLock-" + identifier;
606
- process.locks.lock(exclusiveLockKey, function (releaseLockFn) {
606
+ process.locks.lock(exclusiveLockKey, function (err, releaseLockFn) {
607
607
 
608
608
  var firstRunCacheKey = "firstRun-" + identifier;
609
609
  process.cache.read(firstRunCacheKey, function(err, value) {
@@ -1777,10 +1777,11 @@ var zip = exports.zip = function(directoryPath, writableStream)
1777
1777
  * @param {string} protocol
1778
1778
  * @param {string} host
1779
1779
  * @param [number|string] port
1780
+ * @param {string} path
1780
1781
  *
1781
1782
  * @type {Function}
1782
1783
  */
1783
- var asURL = exports.asURL = function(protocol, host, port)
1784
+ var asURL = exports.asURL = function(protocol, host, port, path)
1784
1785
  {
1785
1786
  // protocol lower case
1786
1787
  protocol = protocol.toLowerCase();
@@ -1806,6 +1807,19 @@ var asURL = exports.asURL = function(protocol, host, port)
1806
1807
  }
1807
1808
  }
1808
1809
 
1810
+ // include url "path" if defined
1811
+ if (path) {
1812
+ path = '/' + path;
1813
+ path = path.replace(/\/+/g, '/'); // ensure no extra '/' characters
1814
+ if (path.endsWith('/')) {
1815
+ // remove trailing '/' character
1816
+ path = path.substring(0, path.length - 1);
1817
+ }
1818
+ if (path) {
1819
+ url += path;
1820
+ }
1821
+ }
1822
+
1809
1823
  return url;
1810
1824
  };
1811
1825