cloudcms-server 0.9.301 → 3.2.278
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.
- package/.last_command +7 -0
- package/LICENSE +1 -1
- package/README.md +1 -1
- package/broadcast/providers/redis.js +24 -49
- package/clients/nrp.js +117 -0
- package/clients/redis.js +64 -0
- package/framework/controllers.js +4 -4
- package/index.js +13 -10
- package/insight/insight.js +1 -1
- package/launchpad/index.js +174 -11
- package/launchpad/launchers/cluster.js +103 -110
- package/launchpad/launchers/redis.js +70 -0
- package/launchpad/launchers/single.js +36 -22
- package/locks/locks.js +53 -7
- package/locks/providers/cluster.js +3 -1
- package/locks/providers/memory.js +10 -7
- package/locks/providers/redis.js +62 -82
- package/middleware/admin/admin.js +2 -2
- package/middleware/authentication/adapters/session.js +11 -8
- package/middleware/authentication/authentication.js +28 -16
- package/middleware/authentication/authenticators/default.js +5 -2
- package/middleware/authentication/authenticators/session.js +5 -2
- package/middleware/authentication/providers/saml.js +1 -1
- package/middleware/authorization/authorization.js +11 -8
- package/middleware/awareness/awareness.js +51 -29
- package/middleware/awareness/plugins/editorial.js +4 -4
- package/middleware/awareness/providers/abstract-async.js +107 -84
- package/middleware/awareness/providers/abstract.js +1 -1
- package/middleware/awareness/providers/memory.js +0 -14
- package/middleware/awareness/providers/redis.js +186 -279
- package/middleware/cache/providers/redis.js +127 -89
- package/middleware/cloudcms/cloudcms.js +22 -16
- package/middleware/form/form.js +2 -2
- package/middleware/proxy/proxy.js +7 -21
- package/middleware/stores/stores.js +2 -2
- package/middleware/virtual-config/virtual-config.js +7 -7
- package/middleware/wcm/wcm.js +4 -4
- package/package.json +53 -51
- package/server/index.js +517 -399
- package/server/standalone.js +9 -0
- package/temp/clusterlock/index.js +3 -3
- package/temp/clusterlock/package.json +1 -1
- package/temp/passport-saml/LICENSE +23 -0
- package/temp/passport-saml/README.md +406 -0
- package/temp/passport-saml/lib/node-saml/algorithms.d.ts +5 -0
- package/temp/passport-saml/lib/node-saml/algorithms.js +41 -0
- package/temp/passport-saml/lib/node-saml/algorithms.js.map +1 -0
- package/temp/passport-saml/lib/node-saml/index.d.ts +3 -0
- package/temp/passport-saml/lib/node-saml/index.js +6 -0
- package/temp/passport-saml/lib/node-saml/index.js.map +1 -0
- package/temp/passport-saml/lib/node-saml/inmemory-cache-provider.d.ts +45 -0
- package/temp/passport-saml/lib/node-saml/inmemory-cache-provider.js +86 -0
- package/temp/passport-saml/lib/node-saml/inmemory-cache-provider.js.map +1 -0
- package/temp/passport-saml/lib/node-saml/saml-post-signing.d.ts +3 -0
- package/temp/passport-saml/lib/node-saml/saml-post-signing.js +15 -0
- package/temp/passport-saml/lib/node-saml/saml-post-signing.js.map +1 -0
- package/temp/passport-saml/lib/node-saml/saml.d.ts +77 -0
- package/temp/passport-saml/lib/node-saml/saml.js +1170 -0
- package/temp/passport-saml/lib/node-saml/saml.js.map +1 -0
- package/temp/passport-saml/lib/node-saml/types.d.ts +95 -0
- package/temp/passport-saml/lib/node-saml/types.js +8 -0
- package/temp/passport-saml/lib/node-saml/types.js.map +1 -0
- package/temp/passport-saml/lib/node-saml/utility.d.ts +3 -0
- package/temp/passport-saml/lib/node-saml/utility.js +19 -0
- package/temp/passport-saml/lib/node-saml/utility.js.map +1 -0
- package/temp/passport-saml/lib/node-saml/xml.d.ts +21 -0
- package/temp/passport-saml/lib/node-saml/xml.js +140 -0
- package/temp/passport-saml/lib/node-saml/xml.js.map +1 -0
- package/temp/passport-saml/lib/passport-saml/index.d.ts +6 -0
- package/temp/passport-saml/lib/passport-saml/index.js +11 -0
- package/temp/passport-saml/lib/passport-saml/index.js.map +1 -0
- package/temp/passport-saml/lib/passport-saml/multiSamlStrategy.d.ts +13 -0
- package/temp/passport-saml/lib/passport-saml/multiSamlStrategy.js +63 -0
- package/temp/passport-saml/lib/passport-saml/multiSamlStrategy.js.map +1 -0
- package/temp/passport-saml/lib/passport-saml/strategy.d.ts +20 -0
- package/temp/passport-saml/lib/passport-saml/strategy.js +167 -0
- package/temp/passport-saml/lib/passport-saml/strategy.js.map +1 -0
- package/temp/passport-saml/lib/passport-saml/types.d.ts +51 -0
- package/temp/passport-saml/lib/passport-saml/types.js +11 -0
- package/temp/passport-saml/lib/passport-saml/types.js.map +1 -0
- package/temp/passport-saml/package.json +96 -0
- package/util/auth.js +1 -1
- package/util/cloudcms.js +72 -93
- package/util/proxy-factory.js +230 -260
- package/util/redis.js +113 -0
- package/util/renditions.js +1 -1
- package/util/util.js +15 -2
- package/launchpad/launchers/sticky-cluster.js +0 -43
- package/web/cms/ice.js +0 -109
- package/web/cms/preview.js +0 -106
- package/web/socket.io/socket.io.js +0 -2
package/.last_command
ADDED
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
var
|
|
1
|
+
var redisClientFactory = require("../../clients/redis");
|
|
2
|
+
var redisHelper = require("../../util/redis");
|
|
2
3
|
|
|
3
|
-
var NRP = require(
|
|
4
|
-
|
|
5
|
-
var logFactory = require("../../util/logger");
|
|
4
|
+
var NRP = require("../../clients/nrp");
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* Redis broadcast provider.
|
|
@@ -12,55 +11,31 @@ var logFactory = require("../../util/logger");
|
|
|
12
11
|
exports = module.exports = function(broadcastConfig)
|
|
13
12
|
{
|
|
14
13
|
var nrp = null;
|
|
15
|
-
|
|
16
|
-
var logger =
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
// allow for global redis default
|
|
20
|
-
// allow for redis broadcast specific
|
|
21
|
-
// otherwise default to "error"
|
|
22
|
-
if (typeof(process.env.CLOUDCMS_REDIS_DEBUG_LEVEL) !== "undefined") {
|
|
23
|
-
logger.setLevel(("" + process.env.CLOUDCMS_REDIS_DEBUG_LEVEL).toLowerCase(), true);
|
|
24
|
-
}
|
|
25
|
-
else if (typeof(process.env.CLOUDCMS_BROADCAST_REDIS_DEBUG_LEVEL) !== "undefined") {
|
|
26
|
-
logger.setLevel(("" + process.env.CLOUDCMS_BROADCAST_REDIS_DEBUG_LEVEL).toLowerCase(), true);
|
|
27
|
-
}
|
|
28
|
-
|
|
14
|
+
|
|
15
|
+
var logger = redisHelper.redisLogger("REDIS_BROADCAST", "CLOUDCMS_BROADCAST_", "error")
|
|
16
|
+
|
|
29
17
|
var r = {};
|
|
30
18
|
|
|
31
19
|
r.start = function(callback)
|
|
32
20
|
{
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
var nrpConfig = {
|
|
54
|
-
"port": redisPort,
|
|
55
|
-
"host": redisEndpoint,
|
|
56
|
-
"scope": "broadcast_cache"
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
logger.info("using config = " + nrpConfig);
|
|
60
|
-
|
|
61
|
-
nrp = new NRP(nrpConfig);
|
|
62
|
-
|
|
63
|
-
callback();
|
|
21
|
+
redisClientFactory.create(broadcastConfig, function(err, client) {
|
|
22
|
+
|
|
23
|
+
if (err) {
|
|
24
|
+
return callback(err);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
var nrpConfig = {
|
|
28
|
+
"client": client,
|
|
29
|
+
"scope": "broadcast_cache"
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
//logger.info("using config = " + nrpConfig);
|
|
33
|
+
|
|
34
|
+
nrp = new NRP(nrpConfig);
|
|
35
|
+
nrp.connect(function(err) {
|
|
36
|
+
callback(err);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
64
39
|
};
|
|
65
40
|
|
|
66
41
|
r.publish = function(topic, message, callback)
|
package/clients/nrp.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// a revision of
|
|
2
|
+
// https://raw.githubusercontent.com/louischatriot/node-redis-pubsub/master/lib/node-redis-pubsub.js
|
|
3
|
+
// that works with Redis 6+
|
|
4
|
+
|
|
5
|
+
"use strict";
|
|
6
|
+
var redis = require('redis');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Create a new NodeRedisPubsub instance that can subscribe to channels and publish messages
|
|
10
|
+
* @param {Object} options Options for the client creations:
|
|
11
|
+
* client - a connected Redis client
|
|
12
|
+
* scope - Optional, two NodeRedisPubsubs with different scopes will not share messages
|
|
13
|
+
*/
|
|
14
|
+
function NodeRedisPubsub(options)
|
|
15
|
+
{
|
|
16
|
+
if (!(this instanceof NodeRedisPubsub)){ return new NodeRedisPubsub(options); }
|
|
17
|
+
|
|
18
|
+
options || (options = {});
|
|
19
|
+
|
|
20
|
+
this.emitter = options.client.duplicate();
|
|
21
|
+
this.emitter.setMaxListeners(0);
|
|
22
|
+
this.receiver = options.client.duplicate();
|
|
23
|
+
this.receiver.setMaxListeners(0);
|
|
24
|
+
|
|
25
|
+
this.prefix = options.scope ? options.scope + ':' : '';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
NodeRedisPubsub.prototype.connect = function(callback)
|
|
29
|
+
{
|
|
30
|
+
var self = this;
|
|
31
|
+
|
|
32
|
+
(async function() {
|
|
33
|
+
await self.emitter.connect();
|
|
34
|
+
await self.receiver.connect();
|
|
35
|
+
callback();
|
|
36
|
+
})();
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Subscribe to a channel
|
|
41
|
+
* @param {String} channel The channel to subscribe to, can be a pattern e.g. 'user.*'
|
|
42
|
+
* @param {Function} handler Function to call with the received message.
|
|
43
|
+
* @param {Function} cb Optional callback to call once the handler is registered.
|
|
44
|
+
*/
|
|
45
|
+
NodeRedisPubsub.prototype.on = NodeRedisPubsub.prototype.subscribe = function(channel, handler, callback)
|
|
46
|
+
{
|
|
47
|
+
if (!callback)
|
|
48
|
+
{
|
|
49
|
+
callback = function(){};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
var self = this;
|
|
53
|
+
|
|
54
|
+
if (channel === "error")
|
|
55
|
+
{
|
|
56
|
+
self.errorHandler = handler;
|
|
57
|
+
self.emitter.on("error", handler);
|
|
58
|
+
self.receiver.on("error", handler);
|
|
59
|
+
return callback();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
var listener = function(self, handler)
|
|
63
|
+
{
|
|
64
|
+
return function(message, channel) {
|
|
65
|
+
|
|
66
|
+
var jsonmsg = message;
|
|
67
|
+
try{
|
|
68
|
+
jsonmsg = JSON.parse(message);
|
|
69
|
+
} catch (ex){
|
|
70
|
+
if(typeof self.errorHandler === 'function'){
|
|
71
|
+
return self.errorHandler("Invalid JSON received! Channel: " + self.prefix + channel + " Message: " + message);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return handler(jsonmsg, channel);
|
|
75
|
+
}
|
|
76
|
+
}(self, handler);
|
|
77
|
+
|
|
78
|
+
(async function() {
|
|
79
|
+
await self.receiver.pSubscribe(self.prefix + channel, listener);
|
|
80
|
+
})();
|
|
81
|
+
|
|
82
|
+
callback();
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Emit an event
|
|
87
|
+
* @param {String} channel Channel on which to emit the message
|
|
88
|
+
* @param {Object} message
|
|
89
|
+
*/
|
|
90
|
+
NodeRedisPubsub.prototype.emit = NodeRedisPubsub.prototype.publish = function (channel, message)
|
|
91
|
+
{
|
|
92
|
+
var self = this;
|
|
93
|
+
|
|
94
|
+
(async function() {
|
|
95
|
+
return await self.emitter.publish(self.prefix + channel, JSON.stringify(message));
|
|
96
|
+
})();
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Safely close the redis connections 'soon'
|
|
101
|
+
*/
|
|
102
|
+
NodeRedisPubsub.prototype.quit = function()
|
|
103
|
+
{
|
|
104
|
+
this.emitter.quit();
|
|
105
|
+
this.receiver.quit();
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Dangerously close the redis connections immediately
|
|
110
|
+
*/
|
|
111
|
+
NodeRedisPubsub.prototype.end = function()
|
|
112
|
+
{
|
|
113
|
+
this.emitter.end(true);
|
|
114
|
+
this.receiver.end(true);
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
module.exports = NodeRedisPubsub;
|
package/clients/redis.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
//var redis = require("redis");
|
|
2
|
+
var redisHelper = require("../util/redis");
|
|
3
|
+
|
|
4
|
+
var clients = {};
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Redis client factory.
|
|
8
|
+
*
|
|
9
|
+
* @type {*}
|
|
10
|
+
*/
|
|
11
|
+
exports = module.exports = {};
|
|
12
|
+
|
|
13
|
+
var create = exports.create = function(config, baseOptions, callback)
|
|
14
|
+
{
|
|
15
|
+
if (typeof(config) === "function") {
|
|
16
|
+
callback = config;
|
|
17
|
+
config = {};
|
|
18
|
+
baseOptions = {};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (typeof(baseOptions) === "function") {
|
|
22
|
+
callback = baseOptions;
|
|
23
|
+
baseOptions = {};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (!config) {
|
|
27
|
+
config = {};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (!baseOptions) {
|
|
31
|
+
baseOptions = {};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
var redisOptions = redisHelper.redisOptions(config);
|
|
35
|
+
if (baseOptions) {
|
|
36
|
+
for (var k in baseOptions) {
|
|
37
|
+
redisOptions[k] = baseOptions[k];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
var url = redisOptions.url;
|
|
42
|
+
|
|
43
|
+
// cached client?
|
|
44
|
+
var client = clients[url];
|
|
45
|
+
if (client) {
|
|
46
|
+
return callback(null, client);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// connect
|
|
50
|
+
(async function() {
|
|
51
|
+
await redisHelper.createAndConnect(redisOptions, function(err, client) {
|
|
52
|
+
|
|
53
|
+
if (err) {
|
|
54
|
+
return callback(err);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// cache it
|
|
58
|
+
clients[url] = client;
|
|
59
|
+
|
|
60
|
+
// return
|
|
61
|
+
return callback(null, client);
|
|
62
|
+
});
|
|
63
|
+
})();
|
|
64
|
+
};
|
package/framework/controllers.js
CHANGED
|
@@ -163,10 +163,10 @@ var handleInvalidate = function(req, res)
|
|
|
163
163
|
// new timestamp
|
|
164
164
|
process.env.CLOUDCMS_APPSERVER_TIMESTAMP = new Date().getTime();
|
|
165
165
|
|
|
166
|
-
// update all socket clients
|
|
167
|
-
process.IO.sockets.emit("timestamp", {
|
|
168
|
-
|
|
169
|
-
});
|
|
166
|
+
// // update all socket clients
|
|
167
|
+
// process.IO.sockets.emit("timestamp", {
|
|
168
|
+
// "timestamp": process.env.CLOUDCMS_APPSERVER_TIMESTAMP
|
|
169
|
+
// });
|
|
170
170
|
|
|
171
171
|
console.log("Server timestamp regenerated");
|
|
172
172
|
|
package/index.js
CHANGED
|
@@ -34,7 +34,7 @@ process.logInfo = process.log = function(text, level)
|
|
|
34
34
|
var Gitana = require("gitana");
|
|
35
35
|
|
|
36
36
|
// default http timeout
|
|
37
|
-
process.defaultHttpTimeoutMs =
|
|
37
|
+
process.defaultHttpTimeoutMs = 60000;
|
|
38
38
|
|
|
39
39
|
if (process.env.DEFAULT_HTTP_TIMEOUT_MS)
|
|
40
40
|
{
|
|
@@ -54,20 +54,18 @@ var HttpsKeepAliveAgent = require('agentkeepalive').HttpsAgent;
|
|
|
54
54
|
http.globalAgent = new HttpKeepAliveAgent({
|
|
55
55
|
keepAlive: true,
|
|
56
56
|
keepAliveMsecs: 1000,
|
|
57
|
-
|
|
57
|
+
maxSockets: 16000,
|
|
58
|
+
maxFreeSockets: 256,
|
|
58
59
|
timeout: process.defaultHttpTimeoutMs,
|
|
59
|
-
|
|
60
|
-
maxFreeSockets: 40,
|
|
61
|
-
rejectUnauthorized: false
|
|
60
|
+
freeSocketTimeout: 30000
|
|
62
61
|
});
|
|
63
62
|
https.globalAgent = new HttpsKeepAliveAgent({
|
|
64
63
|
keepAlive: true,
|
|
65
64
|
keepAliveMsecs: 1000,
|
|
66
|
-
|
|
65
|
+
maxSockets: 16000,
|
|
66
|
+
maxFreeSockets: 256,
|
|
67
67
|
timeout: process.defaultHttpTimeoutMs,
|
|
68
|
-
|
|
69
|
-
maxFreeSockets: 40,
|
|
70
|
-
rejectUnauthorized: false
|
|
68
|
+
freeSocketTimeout: 30000
|
|
71
69
|
});
|
|
72
70
|
|
|
73
71
|
// disable for now
|
|
@@ -138,6 +136,7 @@ exports = module.exports = function()
|
|
|
138
136
|
// not already specified
|
|
139
137
|
var defaultGitanaProxyScheme = "https";
|
|
140
138
|
var defaultGitanaProxyHost = "api.cloudcms.com";
|
|
139
|
+
var defaultGitanaProxyPath = "";
|
|
141
140
|
var defaultGitanaProxyPort = 443;
|
|
142
141
|
|
|
143
142
|
var gitanaJsonPath = path.join(process.env.CLOUDCMS_APPSERVER_BASE_PATH, "gitana.json");
|
|
@@ -149,6 +148,7 @@ exports = module.exports = function()
|
|
|
149
148
|
var parsedUrl = url.parse(gitanaJson.baseURL);
|
|
150
149
|
|
|
151
150
|
defaultGitanaProxyHost = parsedUrl.hostname;
|
|
151
|
+
defaultGitanaProxyPath = parsedUrl.path;
|
|
152
152
|
defaultGitanaProxyScheme = parsedUrl.protocol.substring(0, parsedUrl.protocol.length - 1); // remove the :
|
|
153
153
|
|
|
154
154
|
if (parsedUrl.port)
|
|
@@ -173,13 +173,16 @@ exports = module.exports = function()
|
|
|
173
173
|
if (!process.env.GITANA_PROXY_HOST) {
|
|
174
174
|
process.env.GITANA_PROXY_HOST = defaultGitanaProxyHost;
|
|
175
175
|
}
|
|
176
|
+
if (!process.env.GITANA_PROXY_PATH) {
|
|
177
|
+
process.env.GITANA_PROXY_PATH = defaultGitanaProxyPath;
|
|
178
|
+
}
|
|
176
179
|
if (!process.env.GITANA_PROXY_PORT) {
|
|
177
180
|
process.env.GITANA_PROXY_PORT = defaultGitanaProxyPort;
|
|
178
181
|
}
|
|
179
182
|
|
|
180
183
|
if (cluster.isMaster)
|
|
181
184
|
{
|
|
182
|
-
process.log("Gitana Proxy pointed to: " + util.asURL(process.env.GITANA_PROXY_SCHEME, process.env.GITANA_PROXY_HOST, process.env.GITANA_PROXY_PORT));
|
|
185
|
+
process.log("Gitana Proxy pointed to: " + util.asURL(process.env.GITANA_PROXY_SCHEME, process.env.GITANA_PROXY_HOST, process.env.GITANA_PROXY_PORT, process.env.GITANA_PROXY_PATH));
|
|
183
186
|
}
|
|
184
187
|
|
|
185
188
|
// all web modules are included by default
|
package/insight/insight.js
CHANGED
|
@@ -131,7 +131,7 @@ var doSend = function(callback)
|
|
|
131
131
|
}
|
|
132
132
|
|
|
133
133
|
// url over to cloud cms
|
|
134
|
-
var URL = util.asURL(process.env.GITANA_PROXY_SCHEME, process.env.GITANA_PROXY_HOST, process.env.GITANA_PROXY_PORT) + "/warehouses/" + warehouseId + "/interactions/_create";
|
|
134
|
+
var URL = util.asURL(process.env.GITANA_PROXY_SCHEME, process.env.GITANA_PROXY_HOST, process.env.GITANA_PROXY_PORT, process.env.GITANA_PROXY_PATH) + "/warehouses/" + warehouseId + "/interactions/_create";
|
|
135
135
|
var requestConfig = {
|
|
136
136
|
"url": URL,
|
|
137
137
|
"qs": {},
|
package/launchpad/index.js
CHANGED
|
@@ -1,17 +1,180 @@
|
|
|
1
|
-
|
|
1
|
+
const cluster = require("cluster");
|
|
2
|
+
|
|
3
|
+
// Handle uncaught exceptions...
|
|
4
|
+
process.on('uncaughtException', function(err, source) {
|
|
5
|
+
// if (err === "read ECONNRESET")
|
|
6
|
+
// {
|
|
7
|
+
// // skip
|
|
8
|
+
// }
|
|
9
|
+
// else
|
|
10
|
+
// {
|
|
11
|
+
console.log(`Launchpad - process received event 'uncaughtException': ${err}, source: ${source}`);
|
|
12
|
+
console.log(err.stack);
|
|
13
|
+
// }
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
module.exports = function(type, config, options)
|
|
2
17
|
{
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
options.setup = process.env.CLOUDCMS_LAUNCHPAD_SETUP;
|
|
18
|
+
if (!type) {
|
|
19
|
+
type = process.env.CLOUDCMS_LAUNCHPAD_SETUP;
|
|
6
20
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
21
|
+
if (!type) {
|
|
22
|
+
type = "single";
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
process.env.CLOUDCMS_LAUNCHPAD_SETUP = type
|
|
26
|
+
|
|
27
|
+
var launcherFactory = require("./launchers/" + type);
|
|
28
|
+
if (!launcherFactory)
|
|
29
|
+
{
|
|
30
|
+
throw new Error("Cannot find launcher factory: " + type);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
var launcher = launcherFactory(config);
|
|
34
|
+
|
|
35
|
+
var reportFn = options.report;
|
|
36
|
+
if (!reportFn) {
|
|
37
|
+
options.report = reportFn = function () {};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
var completionFn = options.complete;
|
|
41
|
+
if (!completionFn) {
|
|
42
|
+
options.complete = completionFn = function(err) {
|
|
43
|
+
throw new Error(err);
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
var fork = true;
|
|
48
|
+
if (type === "single") {
|
|
49
|
+
fork = false;
|
|
11
50
|
}
|
|
51
|
+
|
|
52
|
+
if (!fork)
|
|
53
|
+
{
|
|
54
|
+
return launchWorker(launcher, config, options, function(err, app, httpServer) {
|
|
55
|
+
|
|
56
|
+
if (err) {
|
|
57
|
+
return completionFn(config, err);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
var httpServerPort = -1;
|
|
61
|
+
// if (app) {
|
|
62
|
+
// httpServerPort = app.get("port");
|
|
63
|
+
// }
|
|
64
|
+
if (httpServerPort === -1) {
|
|
65
|
+
httpServerPort = process.env.PORT;
|
|
66
|
+
}
|
|
67
|
+
if (httpServerPort === -1) {
|
|
68
|
+
httpServerPort = 3000;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
httpServer.listen(httpServerPort);
|
|
72
|
+
|
|
73
|
+
reportFn(config);
|
|
74
|
+
completionFn(config);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
else
|
|
78
|
+
{
|
|
79
|
+
if (cluster.isMaster)
|
|
80
|
+
{
|
|
81
|
+
return launchMaster(launcher, config, options, function(err, workers) {
|
|
82
|
+
|
|
83
|
+
if (err) {
|
|
84
|
+
return completionFn(config, err);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
//reportFn(config);
|
|
88
|
+
completionFn(config);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
else
|
|
92
|
+
{
|
|
93
|
+
return launchWorker(launcher, config, options, function(err) {
|
|
94
|
+
completionFn(config, err);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
var launchMaster = function(launcher, config, options, done)
|
|
101
|
+
{
|
|
102
|
+
var createHttpServer = options.createHttpServer;
|
|
103
|
+
|
|
104
|
+
createHttpServer(null, function(err, httpServer) {
|
|
105
|
+
|
|
106
|
+
if (err) {
|
|
107
|
+
return done(err);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
launcher.startCluster(httpServer, function(err) {
|
|
111
|
+
|
|
112
|
+
if (err) {
|
|
113
|
+
return done(err);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
var httpServerPort = -1;
|
|
117
|
+
// if (app) {
|
|
118
|
+
// httpServerPort = app.get("port");
|
|
119
|
+
// }
|
|
120
|
+
if (httpServerPort === -1) {
|
|
121
|
+
httpServerPort = process.env.PORT;
|
|
122
|
+
}
|
|
123
|
+
if (httpServerPort === -1) {
|
|
124
|
+
httpServerPort = 3000;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
httpServer.listen(httpServerPort);
|
|
128
|
+
|
|
129
|
+
launcher.afterStartCluster(httpServer, function(err, workers) {
|
|
130
|
+
done(err, workers);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
};
|
|
12
135
|
|
|
13
|
-
|
|
136
|
+
var launchWorker = function(launcher, config, options, done)
|
|
137
|
+
{
|
|
138
|
+
var startServer = options.startServer;
|
|
139
|
+
|
|
140
|
+
var configureServer = options.configureServer;
|
|
141
|
+
if (!configureServer) {
|
|
142
|
+
options.configureServer = configureServer = function(config, app, httpServer, done) {
|
|
143
|
+
done();
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
startServer(config, function(err, app, httpServer) {
|
|
148
|
+
|
|
149
|
+
if (err) {
|
|
150
|
+
return done(err);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
launcher.afterStartServer(app, httpServer, function(err) {
|
|
154
|
+
|
|
155
|
+
if (err) {
|
|
156
|
+
return done(err);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
configureServer(config, app, httpServer, function(err) {
|
|
160
|
+
|
|
161
|
+
if (err) {
|
|
162
|
+
return done(err);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// if we are on a worker process, then inform the master that we completed
|
|
166
|
+
if (process.send) {
|
|
167
|
+
process.send("worker-startup");
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (process.env["CLUSTER_REPORT"])
|
|
171
|
+
{
|
|
172
|
+
var reportFn = options.report;
|
|
173
|
+
reportFn(config);
|
|
174
|
+
}
|
|
14
175
|
|
|
15
|
-
|
|
16
|
-
|
|
176
|
+
done(null, app, httpServer);
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
});
|
|
17
180
|
};
|