2019-10-27 05:52:19 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
require("./lib/compat");
|
2019-10-28 07:06:43 +00:00
|
|
|
var cluster = require("cluster");
|
2019-10-27 05:52:19 +00:00
|
|
|
|
|
|
|
// Greenlock Express
|
|
|
|
var GLE = module.exports;
|
|
|
|
|
2019-10-28 07:06:43 +00:00
|
|
|
// Node's cluster is awesome, because it encourages writing scalable services.
|
|
|
|
//
|
|
|
|
// The point of this provide an API that is consistent between single-process
|
|
|
|
// and multi-process services so that beginners can more easily take advantage
|
|
|
|
// of what cluster has to offer.
|
|
|
|
//
|
|
|
|
// This API provides just enough abstraction to make it easy, but leaves just
|
|
|
|
// enough hoopla so that there's not a large gap in understanding what happens
|
|
|
|
// under the hood. That's the hope, anyway.
|
|
|
|
|
|
|
|
GLE.init = function(fn) {
|
2019-11-07 01:17:37 +00:00
|
|
|
if (false !== fn.cluster && cluster.isWorker) {
|
2019-11-01 21:14:07 +00:00
|
|
|
// ignore the init function and launch the worker
|
|
|
|
return require("./worker.js").create();
|
|
|
|
}
|
|
|
|
|
2019-11-05 18:50:38 +00:00
|
|
|
var opts;
|
|
|
|
if ("function" === typeof fn) {
|
|
|
|
opts = fn();
|
|
|
|
} else if ("object" === typeof fn) {
|
|
|
|
opts = fn;
|
|
|
|
}
|
2019-11-01 21:14:07 +00:00
|
|
|
if (!opts || "object" !== typeof opts) {
|
2019-11-05 18:50:38 +00:00
|
|
|
throw new Error("the `Greenlock.init(fn)` function should return an object `{ packageRoot, cluster }`");
|
2019-11-01 21:14:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// just for ironic humor
|
|
|
|
["cloudnative", "cloudscale", "webscale", "distributed", "blockchain"].forEach(function(k) {
|
|
|
|
if (opts[k]) {
|
|
|
|
opts.cluster = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (opts.cluster) {
|
|
|
|
return require("./master.js").create(opts);
|
|
|
|
}
|
|
|
|
|
|
|
|
return require("./single.js").create(opts);
|
2019-10-27 05:52:19 +00:00
|
|
|
};
|