| 
									
										
										
										
											2019-10-26 23:52:19 -06:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | require("./lib/compat"); | 
					
						
							| 
									
										
										
										
											2019-10-28 01:06:43 -06:00
										 |  |  | var cluster = require("cluster"); | 
					
						
							| 
									
										
										
										
											2019-10-26 23:52:19 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | // Greenlock Express
 | 
					
						
							|  |  |  | var GLE = module.exports; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-28 01:06:43 -06: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-01 15:14:07 -06:00
										 |  |  |     if (cluster.isWorker) { | 
					
						
							|  |  |  |         // ignore the init function and launch the worker
 | 
					
						
							|  |  |  |         return require("./worker.js").create(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     var opts = fn(); | 
					
						
							|  |  |  |     if (!opts || "object" !== typeof opts) { | 
					
						
							| 
									
										
										
										
											2019-11-05 03:09:42 -07:00
										 |  |  |         throw new Error("the `Greenlock.init(fn)` function should return an object `{ greenlock, cluster }`"); | 
					
						
							| 
									
										
										
										
											2019-11-01 15:14:07 -06: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-26 23:52:19 -06:00
										 |  |  | }; |