cloudcms-server 3.3.1-beta.8 → 4.0.0-beta.1

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 (109) 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/d1/index.js +629 -0
  8. package/d1/index.js.works +203 -0
  9. package/d1/package.json +86 -0
  10. package/d1/package.json.works +14 -0
  11. package/duster/helpers/sample/nyt.js +2 -1
  12. package/framework/controllers.js +4 -4
  13. package/index.js +26 -14
  14. package/insight/insight.js +1 -1
  15. package/launchpad/index.js +203 -11
  16. package/launchpad/launchers/cluster.js +103 -110
  17. package/launchpad/launchers/redis.js +70 -0
  18. package/launchpad/launchers/single.js +36 -22
  19. package/locks/locks.js +63 -9
  20. package/locks/providers/cluster.js +3 -1
  21. package/locks/providers/memory.js +10 -7
  22. package/locks/providers/redis.js +62 -82
  23. package/middleware/admin/admin.js +3 -3
  24. package/middleware/authentication/adapters/session.js +11 -8
  25. package/middleware/authentication/authentication.js +28 -16
  26. package/middleware/authentication/authenticators/default.js +5 -2
  27. package/middleware/authentication/authenticators/session.js +5 -2
  28. package/middleware/authentication/providers/saml.js +1 -1
  29. package/middleware/authorization/authorization.js +11 -8
  30. package/middleware/awareness/awareness.js +55 -31
  31. package/middleware/awareness/plugins/editorial.js +4 -4
  32. package/middleware/awareness/providers/abstract-async.js +107 -84
  33. package/middleware/awareness/providers/abstract.js +1 -1
  34. package/middleware/awareness/providers/memory.js +0 -14
  35. package/middleware/awareness/providers/redis.js +186 -279
  36. package/middleware/cache/cache.js +4 -2
  37. package/middleware/cache/providers/redis.js +127 -89
  38. package/middleware/cache/providers/shared-memory.js +3 -3
  39. package/middleware/cloudcms/cloudcms.js +22 -16
  40. package/middleware/form/form.js +3 -3
  41. package/middleware/modules/modules.js +63 -10
  42. package/middleware/proxy/proxy.js +8 -21
  43. package/middleware/stores/stores.js +48 -5
  44. package/middleware/themes/themes.js +49 -0
  45. package/middleware/virtual-config/virtual-config.js +11 -8
  46. package/middleware/wcm/wcm.js +4 -4
  47. package/notifications/notifications.js +27 -4
  48. package/package.json +30 -25
  49. package/server/index.js +508 -412
  50. package/server/standalone.js +9 -0
  51. package/temp/clusterlock/index.js +3 -3
  52. package/temp/clusterlock/package.json +1 -1
  53. package/temp/passport-saml/LICENSE +23 -0
  54. package/temp/passport-saml/README.md +406 -0
  55. package/temp/passport-saml/lib/node-saml/algorithms.d.ts +5 -0
  56. package/temp/passport-saml/lib/node-saml/algorithms.js +41 -0
  57. package/temp/passport-saml/lib/node-saml/algorithms.js.map +1 -0
  58. package/temp/passport-saml/lib/node-saml/index.d.ts +3 -0
  59. package/temp/passport-saml/lib/node-saml/index.js +6 -0
  60. package/temp/passport-saml/lib/node-saml/index.js.map +1 -0
  61. package/temp/passport-saml/lib/node-saml/inmemory-cache-provider.d.ts +45 -0
  62. package/temp/passport-saml/lib/node-saml/inmemory-cache-provider.js +86 -0
  63. package/temp/passport-saml/lib/node-saml/inmemory-cache-provider.js.map +1 -0
  64. package/temp/passport-saml/lib/node-saml/saml-post-signing.d.ts +3 -0
  65. package/temp/passport-saml/lib/node-saml/saml-post-signing.js +15 -0
  66. package/temp/passport-saml/lib/node-saml/saml-post-signing.js.map +1 -0
  67. package/temp/passport-saml/lib/node-saml/saml.d.ts +77 -0
  68. package/temp/passport-saml/lib/node-saml/saml.js +1170 -0
  69. package/temp/passport-saml/lib/node-saml/saml.js.map +1 -0
  70. package/temp/passport-saml/lib/node-saml/types.d.ts +95 -0
  71. package/temp/passport-saml/lib/node-saml/types.js +8 -0
  72. package/temp/passport-saml/lib/node-saml/types.js.map +1 -0
  73. package/temp/passport-saml/lib/node-saml/utility.d.ts +3 -0
  74. package/temp/passport-saml/lib/node-saml/utility.js +19 -0
  75. package/temp/passport-saml/lib/node-saml/utility.js.map +1 -0
  76. package/temp/passport-saml/lib/node-saml/xml.d.ts +21 -0
  77. package/temp/passport-saml/lib/node-saml/xml.js +140 -0
  78. package/temp/passport-saml/lib/node-saml/xml.js.map +1 -0
  79. package/temp/passport-saml/lib/passport-saml/index.d.ts +6 -0
  80. package/temp/passport-saml/lib/passport-saml/index.js +11 -0
  81. package/temp/passport-saml/lib/passport-saml/index.js.map +1 -0
  82. package/temp/passport-saml/lib/passport-saml/multiSamlStrategy.d.ts +13 -0
  83. package/temp/passport-saml/lib/passport-saml/multiSamlStrategy.js +63 -0
  84. package/temp/passport-saml/lib/passport-saml/multiSamlStrategy.js.map +1 -0
  85. package/temp/passport-saml/lib/passport-saml/strategy.d.ts +20 -0
  86. package/temp/passport-saml/lib/passport-saml/strategy.js +167 -0
  87. package/temp/passport-saml/lib/passport-saml/strategy.js.map +1 -0
  88. package/temp/passport-saml/lib/passport-saml/types.d.ts +51 -0
  89. package/temp/passport-saml/lib/passport-saml/types.js +11 -0
  90. package/temp/passport-saml/lib/passport-saml/types.js.map +1 -0
  91. package/temp/passport-saml/package.json +96 -0
  92. package/util/auth.js +6 -6
  93. package/util/cloudcms.js +85 -88
  94. package/util/proxy-factory.js +159 -268
  95. package/util/redis.js +113 -0
  96. package/util/renditions.js +12 -6
  97. package/util/request.js +48 -12
  98. package/util/util.js +16 -2
  99. package/launchpad/launchers/sticky-cluster.js +0 -43
  100. package/temp/memored/.jshintrc +0 -4
  101. package/temp/memored/README.md +0 -240
  102. package/temp/memored/demo/demo1.js +0 -37
  103. package/temp/memored/demo/demo2.js +0 -32
  104. package/temp/memored/gulpfile.js +0 -8
  105. package/temp/memored/index.js +0 -343
  106. package/temp/memored/package.json +0 -54
  107. package/temp/memored/spec/memored.spec.js +0 -265
  108. package/web/cms/ice.js +0 -109
  109. package/web/cms/preview.js +0 -106
package/server/index.js CHANGED
@@ -16,19 +16,20 @@ 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");
26
30
 
27
31
  var requestParam = require("request-param")();
28
32
 
29
- var app = express();
30
- app.disable('x-powered-by');
31
-
32
33
  // cloudcms app server support
33
34
  var main = require("../index");
34
35
 
@@ -37,17 +38,31 @@ var duster = require("../duster/index");
37
38
 
38
39
  var coreHelpers = require("../duster/helpers/core/index");
39
40
 
40
- var toobusy = require("toobusy-js");
41
- toobusy.maxLag(500); // 500 ms lag in event queue, quite high but usable for now
42
- toobusy.interval(250);
41
+ var helmet = require("helmet");
43
42
 
44
43
  var responseTime = require("response-time");
45
44
 
45
+ // safely checks for the existence of a path
46
+ var safeExists = function(_path)
47
+ {
48
+ var exists = false;
49
+ try
50
+ {
51
+ exists = fs.existsSync(_path);
52
+ }
53
+ catch (e)
54
+ {
55
+ // swallow
56
+ }
57
+
58
+ return exists;
59
+ }
60
+
46
61
  var requestCounter = 0;
47
62
 
48
63
  // holds configuration settings
49
64
  var SETTINGS = {
50
- "setup": "single", // single, cluster, sticky-cluster
65
+ "setup": "single", // single, cluster, redis
51
66
  "name": "Cloud CMS Application Server",
52
67
  "socketFunctions": [],
53
68
  "routeFunctions": [],
@@ -110,6 +125,7 @@ var SETTINGS = {
110
125
  "web": "app",
111
126
  "content": "tmp",
112
127
  "templates": "app",
128
+ "themes": "app",
113
129
  "modules": "app"
114
130
  },
115
131
  "virtual": {
@@ -118,6 +134,7 @@ var SETTINGS = {
118
134
  "web": "tmp",
119
135
  "content": "tmp",
120
136
  "templates": "tmp",
137
+ "themes": "tmp",
121
138
  "modules": "tmp"
122
139
  },
123
140
  "oneteam": {
@@ -126,6 +143,7 @@ var SETTINGS = {
126
143
  "web": "app",
127
144
  "content": "hosts_fs",
128
145
  "templates": "app",
146
+ "themes": "hosts_fs",
129
147
  "modules": "hosts_fs"
130
148
  },
131
149
  "net-development": {
@@ -134,6 +152,7 @@ var SETTINGS = {
134
152
  "web": "hosts_fs",
135
153
  "content": "hosts_fs",
136
154
  "templates": "hosts_fs",
155
+ "themes": "hosts_fs",
137
156
  "modules": "hosts_fs"
138
157
  },
139
158
  "net-production": {
@@ -142,6 +161,7 @@ var SETTINGS = {
142
161
  "web": "hosts_s3fs",
143
162
  "content": "hosts_s3fs",
144
163
  "templates": "hosts_s3fs",
164
+ "themes": "hosts_s3fs",
145
165
  "modules": "hosts_s3fs"
146
166
  },
147
167
  "net-development-s3": {
@@ -149,6 +169,7 @@ var SETTINGS = {
149
169
  "config": "hosts_s3",
150
170
  "web": "hosts_s3",
151
171
  "content": "hosts_s3",
172
+ "themes": "hosts_s3",
152
173
  "templates": "hosts_s3"
153
174
  },
154
175
  "net-development-s3fs": {
@@ -157,6 +178,7 @@ var SETTINGS = {
157
178
  "web": "hosts_s3fs",
158
179
  "content": "hosts_s3fs",
159
180
  "templates": "hosts_s3fs",
181
+ "themes": "hosts_s3fs",
160
182
  "modules": "hosts_s3fs"
161
183
  }
162
184
  },
@@ -292,9 +314,7 @@ var SETTINGS = {
292
314
  //"reapInterval": -1
293
315
  },
294
316
  "awareness": {
295
- "enabled": false,
296
- "type": "memory",
297
- "config": {}
317
+ "enabled": false
298
318
  },
299
319
  "graphql": {
300
320
  "enabled": true,
@@ -304,17 +324,67 @@ var SETTINGS = {
304
324
  }
305
325
  };
306
326
 
327
+ // always push core tag helpers to the front
328
+ SETTINGS.dustFunctions.unshift(coreHelpers);
329
+
330
+ // if SETTINGS.errorFunctions is empty, plug in a default error handler
331
+ if (SETTINGS.errorFunctions.length === 0)
332
+ {
333
+ SETTINGS.errorFunctions.push(main.defaultErrorHandler);
334
+ }
335
+ else
336
+ {
337
+ // otherwise, if they plugged in a custom error handler, make sure we at least have a console logger ahead of it
338
+ // so that things are sure to get logged out to console
339
+ SETTINGS.errorFunctions.unshift(main.consoleErrorLogger);
340
+ }
341
+
342
+ // insert an error handler to handle refresh token failures
343
+ SETTINGS.errorFunctions.unshift(main.refreshTokenErrorHandler);
344
+
345
+ // CLOUDCMS_HOSTS_PATH environment variable
346
+ // assume /hosts with optional fallback to /System/Volumes/Data/hosts for MacOS support
347
+ if (!process.env.CLOUDCMS_HOSTS_PATH)
348
+ {
349
+ process.env.CLOUDCMS_HOSTS_PATH = "/hosts";
350
+
351
+ if (!safeExists(process.env.CLOUDCMS_HOSTS_PATH))
352
+ {
353
+ if (safeExists("/System/Volumes/Data/hosts"))
354
+ {
355
+ process.env.CLOUDCMS_HOSTS_PATH = "/System/Volumes/Data/hosts";
356
+ }
357
+ else
358
+ {
359
+ const homedir = require('os').homedir();
360
+
361
+ if (safeExists(homedir + "/hosts"))
362
+ {
363
+ process.env.CLOUDCMS_HOSTS_PATH = homedir + "/hosts";
364
+ }
365
+ }
366
+ }
367
+ }
368
+
369
+
370
+
371
+
372
+
373
+
374
+
375
+
376
+
377
+
378
+
379
+
380
+
381
+
382
+
383
+
384
+
307
385
  // runs on 2999 by default
308
386
  process.env.PORT = process.env.PORT || 2999;
309
387
 
310
- // allows for specification of alternative transports
311
- SETTINGS.socketTransports = [
312
- 'websocket',
313
- 'xhr-polling',
314
- 'jsonp-polling',
315
- 'polling'
316
- ];
317
-
318
388
  var exports = module.exports;
319
389
 
320
390
  /**
@@ -498,62 +568,19 @@ var _start = function(overrides, callback) {
498
568
  callback = function() {};
499
569
  }
500
570
 
501
- // always push core tag helpers to the front
502
- SETTINGS.dustFunctions.unshift(coreHelpers);
503
-
504
- // if SETTINGS.errorFunctions is empty, plug in a default error handler
505
- if (SETTINGS.errorFunctions.length === 0)
506
- {
507
- SETTINGS.errorFunctions.push(main.defaultErrorHandler);
508
- }
509
- else
510
- {
511
- // otherwise, if they plugged in a custom error handler, make sure we at least have a console logger ahead of it
512
- // so that things are sure to get logged out to console
513
- SETTINGS.errorFunctions.unshift(main.consoleErrorLogger);
514
- }
515
-
516
- // insert an error handler to handle refresh token failures
517
- SETTINGS.errorFunctions.unshift(main.refreshTokenErrorHandler);
518
-
519
571
  // create our master config
520
572
  var config = clone(SETTINGS);
521
573
  if (overrides) {
522
574
  util.merge(overrides, config);
523
575
  }
524
-
525
- // assume for launchpad
526
- if (!config.setup) {
527
- config.setup = "single";
528
- }
529
-
530
- launchPad({
531
- "setup": config.setup,
532
- "factory": function(done) {
533
- startSlave(config, function(app, server) {
534
- done(server);
535
- });
536
- },
537
- "report": function() {
538
- runFunctions(config.reportFunctions, [], function(err) {
539
- // todo
540
- });
541
- },
542
- "complete": function() {
543
- callback();
544
- }
545
- });
546
- };
547
-
548
- var startSlave = function(config, afterStartFn)
549
- {
576
+
550
577
  // set up modes
551
578
  process.env.CLOUDCMS_APPSERVER_MODE = "development";
552
-
553
- if (process.env.NODE_ENV == "production") {
579
+
580
+ if (process.env.NODE_ENV === "production") {
554
581
  process.env.CLOUDCMS_APPSERVER_MODE = "production";
555
582
  }
556
-
583
+
557
584
  /*
558
585
  // set up domain hosting
559
586
  // if not otherwise specified, we assume hosting at *.cloudcms.net
@@ -564,10 +591,10 @@ var startSlave = function(config, afterStartFn)
564
591
  }
565
592
  }
566
593
  */
567
-
594
+
568
595
  // store config on process instance
569
596
  process.configuration = config;
570
-
597
+
571
598
  // some config overrides can come in through process.configuration
572
599
  if (process.configuration) {
573
600
  if (process.configuration.virtualHost && process.configuration.virtualHost.domain) {
@@ -581,111 +608,181 @@ var startSlave = function(config, afterStartFn)
581
608
  if (process.env.CLOUDCMS_VIRTUAL_HOST_DOMAIN) {
582
609
  process.env.CLOUDCMS_VIRTUAL_HOST_DOMAIN = process.env.CLOUDCMS_VIRTUAL_HOST_DOMAIN.toLowerCase();
583
610
  }
584
-
611
+
585
612
  if (!process.env.CLOUDCMS_STANDALONE_HOST) {
586
613
  process.env.CLOUDCMS_STANDALONE_HOST = "local";
587
614
  }
588
-
589
- // session store
590
- var initializedSession = null;
591
- if (process.configuration.session)
592
- {
593
- if (process.configuration.session.enabled)
594
- {
595
- var sessionSecret = process.configuration.session.secret;
596
- if (!sessionSecret) {
597
- sessionSecret = "secret";
598
- }
599
-
600
- var sessionConfig = {
601
- secret: sessionSecret,
602
- resave: false,
603
- saveUninitialized: false
604
- };
605
-
606
- if (process.configuration.session.type === "file")
607
- {
608
- var options = {};
609
- if (process.configuration.session.ttl)
610
- {
611
- options.ttl = process.configuration.session.ttl;
612
- }
613
- if (process.configuration.session.reapInterval)
614
- {
615
- options.reapInterval = process.configuration.session.reapInterval;
616
- }
617
- // session file store
618
- var SessionFileStore = require('session-file-store')(session);
619
- sessionConfig.store = new SessionFileStore(options);
620
- }
621
- else if (process.configuration.session.type === "memory" || !process.configuration.session.type)
622
- {
623
- var options = {};
624
- options.checkPeriod = 86400000; // prune expired entries every 24h
625
-
626
- // session memory store
627
- var MemoryStore = require('memorystore')(session);
628
- sessionConfig.store = new MemoryStore(options);
615
+
616
+
617
+ // auto-configuration for HTTPS
618
+ if (!process.configuration.https) {
619
+ process.configuration.https = {};
620
+ }
621
+ if (process.env.CLOUDCMS_HTTPS) {
622
+ process.configuration.https = JSON.parse(process.env.CLOUDCMS_HTTPS);
623
+ }
624
+ if (process.env.CLOUDCMS_HTTPS_KEY_FILEPATH) {
625
+ process.configuration.https.key = fs.readFileSync(process.env.CLOUDCMS_HTTPS_KEY_FILEPATH);
626
+ }
627
+ if (process.env.CLOUDCMS_HTTPS_CERT_FILEPATH) {
628
+ process.configuration.https.cert = fs.readFileSync(process.env.CLOUDCMS_HTTPS_CERT_FILEPATH);
629
+ }
630
+ if (process.env.CLOUDCMS_HTTPS_PFX_FILEPATH) {
631
+ process.configuration.https.pfx = fs.readFileSync(process.env.CLOUDCMS_HTTPS_PFX_FILEPATH);
632
+ }
633
+ if (process.env.CLOUDCMS_HTTPS_PASSPHRASE) {
634
+ process.configuration.https.passphrase = process.env.CLOUDCMS_HTTPS_PASSPHRASE;
635
+ }
636
+ if (process.env.CLOUDCMS_HTTPS_REQUEST_CERT === "true") {
637
+ process.configuration.https.requestCert = true;
638
+ }
639
+ if (process.env.CLOUDCMS_HTTPS_CA_FILEPATH) {
640
+ process.configuration.https.ca = [ fs.readFileSync(process.env.CLOUDCMS_HTTPS_CA_FILEPATH) ];
641
+ }
642
+
643
+ // if https config is empty, remove it
644
+ if (Object.keys(process.configuration.https).length === 0) {
645
+ delete process.configuration.https;
646
+ }
647
+
648
+
649
+ // auto configuration of session store
650
+ if (!process.configuration.session) {
651
+ process.configuration.session = {};
652
+ }
653
+ // auto-configuration for redis?
654
+ if (process.env.CLOUDCMS_REDIS_URL || (process.env.CLOUDCMS_REDIS_ENDPOINT && process.env.CLOUDCMS_REDIS_PORT)) {
655
+ process.env.CLOUDCMS_SESSION_TYPE = "redis";
656
+ }
657
+
658
+ if (process.env.CLOUDCMS_SESSION_TYPE) {
659
+ process.configuration.session.enabled = true;
660
+ process.configuration.session.type = process.env.CLOUDCMS_SESSION_TYPE;
661
+ }
662
+ if (process.env.CLOUDCMS_SESSION_SECRET) {
663
+ process.configuration.session.secret = process.env.CLOUDCMS_SESSION_SECRET;
664
+ }
665
+
666
+
667
+ // determine the max files
668
+ util.maxFiles(function(err, maxFiles) {
669
+ process.env.CLOUDCMS_MAX_FILES = maxFiles;
670
+
671
+ // assume for launchpad
672
+ if (!config.setup) {
673
+ config.setup = "single";
674
+ }
675
+
676
+ launchPad(config.setup, config, {
677
+ "createHttpServer": function(app, done) {
678
+ createHttpServer(app, function(err, httpServer) {
679
+ done(err, httpServer);
680
+ });
681
+ },
682
+ "startServer": function(config, done) {
683
+ startServer(config, function(err, app, httpServer, httpServerPort) {
684
+ done(err, app, httpServer, httpServerPort);
685
+ });
686
+ },
687
+ "configureServer": function(config, app, httpServer, done) {
688
+ configureServer(config, app, httpServer, function(err) {
689
+ done(err);
690
+ });
691
+ },
692
+ "report": function(config) {
693
+ runFunctions(config.reportFunctions, [], function(err) {
694
+ // todo
695
+ });
696
+ },
697
+ "complete": function(config, err) {
698
+ callback(err);
629
699
  }
700
+ });
701
+ });
702
+ };
630
703
 
631
- initializedSession = session(sessionConfig);
632
- }
704
+ var initSession = function(initDone)
705
+ {
706
+ if (!process.configuration.session) {
707
+ return initDone();
633
708
  }
634
-
635
- // safely checks for the existence of a path
636
- var safeExists = function(_path)
709
+ if (!process.configuration.session.enabled) {
710
+ return initDone();
711
+ }
712
+
713
+ var sessionSecret = process.configuration.session.secret;
714
+ if (!sessionSecret) {
715
+ sessionSecret = "secret";
716
+ }
717
+
718
+ var sessionConfig = {
719
+ secret: sessionSecret,
720
+ resave: false,
721
+ saveUninitialized: false
722
+ };
723
+
724
+ if (process.configuration.session.type) {
725
+ process.configuration.session.type = process.configuration.session.type.toLowerCase();
726
+ }
727
+
728
+ if (process.configuration.session.type === "file")
637
729
  {
638
- var exists = false;
639
- try
730
+ var options = {};
731
+ if (process.configuration.session.ttl)
640
732
  {
641
- exists = fs.existsSync(_path);
733
+ options.ttl = process.configuration.session.ttl;
642
734
  }
643
- catch (e)
735
+ if (process.configuration.session.reapInterval)
644
736
  {
645
- // swallow
737
+ options.reapInterval = process.configuration.session.reapInterval;
646
738
  }
647
-
648
- return exists;
739
+ // session file store
740
+ var SessionFileStore = require('session-file-store')(session);
741
+ sessionConfig.store = new SessionFileStore(options);
742
+ return initDone(null, session(sessionConfig));
649
743
  }
650
-
651
- // CLOUDCMS_HOSTS_PATH environment variable
652
- // assume /hosts with optional fallback to /System/Volumes/Data/hosts for MacOS support
653
- if (!process.env.CLOUDCMS_HOSTS_PATH)
744
+ else if (process.configuration.session.type === "redis")
654
745
  {
655
- process.env.CLOUDCMS_HOSTS_PATH = "/hosts";
656
-
657
- if (!safeExists(process.env.CLOUDCMS_HOSTS_PATH))
658
- {
659
- if (safeExists("/System/Volumes/Data/hosts"))
660
- {
661
- process.env.CLOUDCMS_HOSTS_PATH = "/System/Volumes/Data/hosts";
662
- }
663
- else
664
- {
665
- const homedir = require('os').homedir();
666
-
667
- if (safeExists(homedir + "/hosts"))
668
- {
669
- process.env.CLOUDCMS_HOSTS_PATH = homedir + "/hosts";
670
- }
671
- }
672
- }
746
+ var IORedis = require("ioredis");
747
+ var redisOptions = redisHelper.redisOptions();
748
+ var redisClient = new IORedis(redisOptions.url);
749
+
750
+ var RedisStore = connectRedis(session);
751
+ sessionConfig.store = new RedisStore({ client: redisClient });
752
+ initDone(null, session(sessionConfig));
673
753
  }
754
+ else if (process.configuration.session.type === "memory" || !process.configuration.session.type)
755
+ {
756
+ var options = {};
757
+ options.checkPeriod = 86400000; // prune expired entries every 24h
758
+
759
+ // session memory store
760
+ var MemoryStore = require('memorystore')(session);
761
+ sessionConfig.store = new MemoryStore(options);
762
+ return initDone(null, session(sessionConfig));
763
+ }
764
+ };
674
765
 
675
- // global temp directory
676
- util.createTempDirectory(function(err, tempDirectory) {
677
- process.env.CLOUDCMS_TEMPDIR_PATH = tempDirectory;
678
-
679
- // determine the max files
680
- util.maxFiles(function(err, maxFiles) {
681
-
682
- process.env.CLOUDCMS_MAX_FILES = maxFiles;
766
+ var startServer = function(config, startServerFinishedFn)
767
+ {
768
+ var app = express();
769
+ app.disable('x-powered-by');
770
+
771
+ initSession(function(err, initializedSession) {
683
772
 
773
+ if (err) {
774
+ throw err;
775
+ }
776
+
777
+ // global temp directory
778
+ util.createTempDirectory(function(err, tempDirectory) {
779
+ process.env.CLOUDCMS_TEMPDIR_PATH = tempDirectory;
780
+
684
781
  // global service starts
685
782
  main.init(app, function (err) {
686
-
783
+
687
784
  app.enable('strict routing');
688
-
785
+
689
786
  ////////////////////////////////////////////////////////////////////////////
690
787
  //
691
788
  // BASE CONFIGURATION
@@ -694,15 +791,15 @@ var startSlave = function(config, afterStartFn)
694
791
  // Runs on port 3000 by default
695
792
  //
696
793
  ////////////////////////////////////////////////////////////////////////////
697
-
794
+
698
795
  // all environments
699
796
  app.set('port', process.env.PORT);
700
797
  app.set('views', process.env.CLOUDCMS_APPSERVER_BASE_PATH + "/views");
701
-
798
+
702
799
  if (config.viewEngine === "dust")
703
800
  {
704
801
  var cons = require('consolidate');
705
-
802
+
706
803
  app.set('view engine', 'html');
707
804
  app.set('view engine', 'dust');
708
805
  app.engine('html', cons.dust);
@@ -711,13 +808,13 @@ var startSlave = function(config, afterStartFn)
711
808
  else if (config.viewEngine === "handlebars" || config.viewEngine === "hbs")
712
809
  {
713
810
  var hbs = require('hbs');
714
-
811
+
715
812
  app.set('view engine', 'html');
716
813
  app.set('view engine', 'hbs');
717
814
  app.engine('html', hbs.__express);
718
815
  app.engine('hbs', hbs.__express);
719
816
  }
720
-
817
+
721
818
  ////////////////////////////////////////////////////////////////////////////
722
819
  //
723
820
  // VIRTUAL SUPPORT
@@ -726,26 +823,26 @@ var startSlave = function(config, afterStartFn)
726
823
  // ahead of anything else running.
727
824
  //
728
825
  ////////////////////////////////////////////////////////////////////////////
729
-
826
+
730
827
  // custom morgan logger
731
828
  morgan(function (tokens, req, res) {
732
-
829
+
733
830
  var status = res.statusCode;
734
831
  var len = parseInt(res.getHeader('Content-Length'), 10);
735
832
  var host = req.domainHost;
736
833
  if (req.virtualHost) {
737
834
  host = req.virtualHost;
738
835
  }
739
-
836
+
740
837
  len = isNaN(len) ? '0b' : len = bytes(len);
741
-
838
+
742
839
  var d = new Date();
743
840
  var dateString = d.toDateString();
744
841
  var timeString = d.toTimeString();
745
-
842
+
746
843
  // gray color
747
844
  var grayColor = "\x1b[90m";
748
-
845
+
749
846
  // status color
750
847
  var color = 32;
751
848
  if (status >= 500) {
@@ -758,17 +855,17 @@ var startSlave = function(config, afterStartFn)
758
855
  color = 36;
759
856
  }
760
857
  var statusColor = "\x1b[" + color + "m";
761
-
858
+
762
859
  // final color
763
860
  var finalColor = "\x1b[0m";
764
-
765
- if (process.env.CLOUDCMS_APPSERVER_MODE == "production")
861
+
862
+ if (process.env.CLOUDCMS_APPSERVER_MODE === "production")
766
863
  {
767
864
  grayColor = "";
768
865
  statusColor = "";
769
866
  finalColor = "";
770
867
  }
771
-
868
+
772
869
  var message = '';
773
870
  message += grayColor + '<' + req.id + '> ';
774
871
  message += grayColor + '[' + dateString + ' ' + timeString + '] ';
@@ -780,10 +877,10 @@ var startSlave = function(config, afterStartFn)
780
877
  message += grayColor + req.originalUrl + '" ';
781
878
  message += grayColor + len + ' ';
782
879
  message += finalColor;
783
-
880
+
784
881
  return message;
785
882
  });
786
-
883
+
787
884
  /*
788
885
  // debug headers being set
789
886
  app.use(function(req, res, next) {
@@ -795,58 +892,49 @@ var startSlave = function(config, afterStartFn)
795
892
  next();
796
893
  });
797
894
  */
798
-
799
- // middleware which blocks requests when we're too busy
800
- app.use(function(req, res, next) {
801
- if (toobusy()) {
802
- res.status(503).send("The web application is too busy to serve this request. Please try again.");
803
- } else {
804
- next();
805
- }
806
- });
807
-
808
- // add req.id re
895
+
896
+ // increment and assign request id
809
897
  app.use(function (req, res, next) {
810
898
  requestCounter++;
811
899
  req.id = requestCounter;
812
900
  next();
813
901
  });
814
-
902
+
815
903
  // APPLY CUSTOM INIT FUNCTIONS
816
904
  runFunctions(config.initFunctions, [app], function (err) {
817
-
905
+
818
906
  // retain originalUrl and originalPath since these can get modified along the way
819
907
  app.use(function (req, res, next) {
820
908
  req.originalUrl = req.url;
821
909
  req.originalPath = req.path;
822
910
  next();
823
911
  });
824
-
912
+
825
913
  // req.param method
826
914
  app.use(requestParam);
827
-
915
+
828
916
  // add req.log function
829
917
  app.use(function (req, res, next) {
830
-
918
+
831
919
  req._log = req.log = function (text/*, warn*/) {
832
-
920
+
833
921
  var host = req.domainHost;
834
922
  if (req.virtualHost)
835
923
  {
836
924
  host = req.virtualHost;
837
925
  }
838
-
926
+
839
927
  var timestamp = moment(new Date()).format("MM/DD/YYYY HH:mm:ss Z");
840
928
  var grayColor = "\x1b[90m";
841
929
  var finalColor = "\x1b[0m";
842
-
930
+
843
931
  // in production, don't use colors
844
932
  if (process.env.CLOUDCMS_APPSERVER_MODE === "production")
845
933
  {
846
934
  grayColor = "";
847
935
  finalColor = "";
848
936
  }
849
-
937
+
850
938
  var message = '';
851
939
  message += grayColor + '<' + req.id + '> ';
852
940
  if (cluster.worker && cluster.worker.id)
@@ -857,33 +945,33 @@ var startSlave = function(config, afterStartFn)
857
945
  message += grayColor + host + ' ';
858
946
  message += grayColor + text + '';
859
947
  message += finalColor;
860
-
948
+
861
949
  /*
862
950
  if (warn)
863
951
  {
864
952
  message = "\r\n**** SLOW RESPONSE ****\r\n" + message + "\r\n";
865
953
  }
866
954
  */
867
-
955
+
868
956
  console.log(message);
869
957
  };
870
-
958
+
871
959
  next();
872
960
  });
873
-
961
+
874
962
  // common interceptors and config
875
963
  main.common1(app);
876
-
964
+
877
965
  // general logging of requests
878
966
  // gather statistics on response time
879
967
  app.use(responseTime(function (req, res, time) {
880
-
968
+
881
969
  var warn = false;
882
970
  if (time > 1000)
883
971
  {
884
972
  warn = true;
885
973
  }
886
-
974
+
887
975
  var requestPath = req.originalPath;
888
976
  if (requestPath)
889
977
  {
@@ -901,51 +989,51 @@ var startSlave = function(config, afterStartFn)
901
989
  requestPath = util.stripQueryStringFromUrl(requestPath);
902
990
  }
903
991
  }
904
-
992
+
905
993
  req.log(req.method + " " + requestPath + " [" + res.statusCode + "] (" + time.toFixed(2) + " ms)", warn);
906
994
  }));
907
-
995
+
908
996
  // set up CORS allowances
909
997
  // this lets CORS requests float through the proxy
910
998
  app.use(main.ensureCORS());
911
-
999
+
912
1000
  // set up default security headers
913
1001
  app.use(main.ensureHeaders());
914
-
1002
+
915
1003
  // common interceptors and config
916
1004
  main.common2(app);
917
-
1005
+
918
1006
  // APPLY CUSTOM DRIVER FUNCTIONS
919
1007
  runFunctions(config.driverFunctions, [app], function(err) {
920
-
1008
+
921
1009
  // binds gitana driver into place
922
1010
  main.common3(app);
923
-
1011
+
924
1012
  // parse cookies
925
1013
  app.use(cookieParser());
926
-
1014
+
927
1015
  // cloudcms things need to run here
928
1016
  main.common4(app, true);
929
-
1017
+
930
1018
  // APPLY CUSTOM FILTER FUNCTIONS
931
1019
  runFunctions(config.filterFunctions, [app], function (err) {
932
-
1020
+
933
1021
  // PATH BASED PERFORMANCE CACHING
934
1022
  main.perf1(app);
935
-
1023
+
936
1024
  // proxy - anything that goes to /proxy is handled here early and nothing processes afterwards
937
1025
  main.proxy(app);
938
-
1026
+
939
1027
  // MIMETYPE BASED PERFORMANCE CACHING
940
1028
  main.perf2(app);
941
-
1029
+
942
1030
  // DEVELOPMENT BASED PERFORMANCE CACHING
943
1031
  main.perf3(app);
944
-
1032
+
945
1033
  // standard body parsing + a special cloud cms body parser that makes a last ditch effort for anything
946
1034
  // that might be JSON (regardless of content type)
947
1035
  app.use(function (req, res, next) {
948
-
1036
+
949
1037
  multipart(process.configuration.bodyParsers.multipart || {})(req, res, function (err) {
950
1038
  bodyParser.json(process.configuration.bodyParsers.json || {})(req, res, function (err) {
951
1039
  bodyParser.urlencoded(process.configuration.bodyParsers.urlencoded || {})(req, res, function (err) {
@@ -955,35 +1043,35 @@ var startSlave = function(config, afterStartFn)
955
1043
  });
956
1044
  });
957
1045
  });
958
-
1046
+
959
1047
  });
960
-
1048
+
961
1049
  if (initializedSession)
962
1050
  {
963
1051
  app.use(initializedSession);
964
1052
  app.use(flash());
965
1053
  }
966
-
1054
+
967
1055
  // this is the same as calling
968
1056
  // app.use(passport.initialize());
969
1057
  // except we create a new passport each time and store on request to support multitenancy
970
1058
  app.use(function(req, res, next) {
971
-
1059
+
972
1060
  var passport = new Passport();
973
1061
  passport._key = "passport-" + req.virtualHost;
974
-
1062
+
975
1063
  req._passport = {};
976
1064
  req._passport.instance = passport;
977
-
1065
+
978
1066
  if (req.session && req.session[passport._key])
979
1067
  {
980
1068
  // load data from existing session
981
1069
  req._passport.session = req.session[passport._key];
982
1070
  }
983
-
1071
+
984
1072
  // add this in
985
1073
  req.passport = req._passport.instance;
986
-
1074
+
987
1075
  // passport - serialize and deserialize
988
1076
  req.passport.serializeUser(function(user, done) {
989
1077
  done(null, user);
@@ -991,10 +1079,10 @@ var startSlave = function(config, afterStartFn)
991
1079
  req.passport.deserializeUser(function(user, done) {
992
1080
  done(null, user);
993
1081
  });
994
-
1082
+
995
1083
  next();
996
1084
  });
997
-
1085
+
998
1086
  // passport session
999
1087
  if (initializedSession)
1000
1088
  {
@@ -1002,27 +1090,27 @@ var startSlave = function(config, afterStartFn)
1002
1090
  req.passport.session()(req, res, next);
1003
1091
  });
1004
1092
  }
1005
-
1093
+
1006
1094
  // welcome files
1007
1095
  main.welcome(app);
1008
-
1096
+
1009
1097
  // configure cloudcms app server command handing
1010
1098
  main.interceptors(app, true);
1011
-
1099
+
1012
1100
  //app.use(app.router);
1013
-
1101
+
1014
1102
  // healthcheck middleware
1015
1103
  main.healthcheck(app);
1016
-
1104
+
1017
1105
  // APPLY CUSTOM ROUTES
1018
1106
  runFunctions(config.routeFunctions, [app], function (err) {
1019
-
1107
+
1020
1108
  // configure cloudcms app server handlers
1021
1109
  main.handlers(app, true);
1022
-
1110
+
1023
1111
  // register error functions
1024
1112
  runFunctions(config.errorFunctions, [app], function (err) {
1025
-
1113
+
1026
1114
  // APPLY CUSTOM CONFIGURE FUNCTIONS
1027
1115
  var allConfigureFunctions = [];
1028
1116
  for (var env in config.configureFunctions)
@@ -1037,188 +1125,15 @@ var startSlave = function(config, afterStartFn)
1037
1125
  }
1038
1126
  }
1039
1127
  runFunctions(allConfigureFunctions, [app], function (err) {
1040
-
1041
- ////////////////////////////////////////////////////////////////////////////
1042
- //
1043
- // INITIALIZE THE SERVER
1044
- //
1045
- ////////////////////////////////////////////////////////////////////////////
1046
-
1047
-
1048
- // CORE OBJECTS
1049
- var server = http.Server(app);
1050
-
1051
- // request timeout
1052
- var requestTimeout = 30000; // 30 seconds
1053
- if (process.configuration && process.configuration.timeout)
1054
- {
1055
- requestTimeout = process.configuration.timeout;
1056
- }
1057
- server.setTimeout(requestTimeout);
1058
-
1059
- // socket
1060
- server.on("connection", function (socket) {
1061
- socket.setNoDelay(true);
1062
- });
1063
- var io = process.IO = require("socket.io")(server, {
1064
- "transports": config.socketTransports
1065
- });
1066
- io.use(function (socket, next) {
1067
-
1068
- // console.log("New socket being initialized");
1069
-
1070
- // attach _log function
1071
- socket._log = function (text) {
1072
-
1073
- var host = socket.handshake.headers.host;
1074
- if (socket.handshake.headers["x-forwarded-host"])
1075
- {
1076
- host = socket.handshake.headers["x-forwarded-host"];
1077
- }
1078
-
1079
- var d = new Date();
1080
- var dateString = d.toDateString();
1081
- var timeString = d.toTimeString();
1082
-
1083
- // gray color
1084
- var grayColor = "\x1b[90m";
1085
-
1086
- // final color
1087
- var finalColor = "\x1b[0m";
1088
-
1089
- if (process.env.CLOUDCMS_APPSERVER_MODE === "production")
1090
- {
1091
- grayColor = "";
1092
- finalColor = "";
1093
- }
1094
-
1095
- var message = '';
1096
- message += grayColor + '<socket> ';
1097
- message += grayColor + '[' + dateString + ' ' + timeString + '] ';
1098
- message += grayColor + host + ' ';
1099
- message += grayColor + text + '';
1100
- message += finalColor;
1101
-
1102
- console.log(message);
1103
- };
1104
- /*
1105
- socket.on("connect", function () {
1106
- console.log("Socket connect()");
1107
- });
1108
- */
1109
- /*
1110
- socket.on("disconnect", function () {
1111
- var message = "Socket disconnected";
1112
- if (socket && socket.host)
1113
- {
1114
- message += ", host=" + socket.host;
1115
- }
1116
- if (socket && socket.gitana && socket.gitana.application && socket.gitana.application())
1117
- {
1118
- message += ", application=" + socket.gitana.application().title;
1119
- }
1120
- console.log(message);
1121
- });
1122
- */
1123
-
1124
- // APPLY CUSTOM SOCKET.IO CONFIG
1125
- runFunctions(config.socketFunctions, [socket], function (err) {
1126
-
1127
- require("../middleware/awareness/awareness").initSocketIO(function() {
1128
- next();
1129
- });
1130
-
1131
- // INSIGHT SERVER
1132
- // if (config.insight && config.insight.enabled)
1133
- // {
1134
- // console.log("Init Insight to Socket");
1135
-
1136
- // require("../insight/insight").init(socket, function () {
1137
- // next();
1138
- // });
1139
- // }
1140
- // else
1141
- // {
1142
- // next();
1143
- // }
1144
- });
1145
-
1146
- });
1147
-
1148
- // SET INITIAL VALUE FOR SERVER TIMESTAMP
1149
- process.env.CLOUDCMS_APPSERVER_TIMESTAMP = new Date().getTime();
1150
-
1151
- // DUST
1152
- runFunctions(config.dustFunctions, [app, duster.getDust()], function (err) {
1153
-
1154
- // APPLY SERVER BEFORE START FUNCTIONS
1155
- runFunctions(config.beforeFunctions, [app], function (err) {
1156
-
1157
- server._listenPort = app.get("port");
1158
-
1159
- // AFTER SERVER START
1160
- runFunctions(config.afterFunctions, [app], function (err) {
1161
-
1162
- function cleanup() {
1163
-
1164
- if (cluster.isMaster)
1165
- {
1166
- console.log("");
1167
- console.log("");
1168
-
1169
- console.log("Cloud CMS Module shutting down");
1170
-
1171
- // close server connections as cleanly as we can
1172
- console.log(" -> Closing server connections");
1173
- }
1174
-
1175
- try
1176
- {
1177
- server.close();
1178
- }
1179
- catch (e)
1180
- {
1181
- console.log("Server.close produced error: " + JSON.stringify(e));
1182
- }
1183
-
1184
- // ask toobusy to shut down as cleanly as we can
1185
- if (cluster.isMaster)
1186
- {
1187
- console.log(" -> Closing toobusy monitor");
1188
- }
1189
-
1190
- try
1191
- {
1192
- toobusy.shutdown();
1193
- }
1194
- catch (e)
1195
- {
1196
- console.log("toobusy.shutdown produced error: " + JSON.stringify(e));
1197
- }
1198
-
1199
- if (cluster.isMaster)
1200
- {
1201
- console.log("");
1202
- }
1203
-
1204
- // tell the process to exit
1205
- process.exit();
1206
- }
1207
-
1208
- // listen for kill or interrupt so that we can shut down cleanly
1209
- process.on('SIGINT', cleanup);
1210
- process.on('SIGTERM', cleanup);
1211
-
1212
- // if we are on a worker process, then inform the master that we completed
1213
- if (process.send)
1214
- {
1215
- process.send("server-startup");
1216
- }
1217
-
1218
- afterStartFn(app, server);
1219
-
1220
- });
1221
- });
1128
+
1129
+ // create the server (either HTTP or HTTPS)
1130
+ createHttpServer(app, function(err, httpServer) {
1131
+
1132
+ if (err) {
1133
+ return startServerFinishedFn(err);
1134
+ }
1135
+
1136
+ startServerFinishedFn(null, app, httpServer);
1222
1137
  });
1223
1138
  });
1224
1139
  });
@@ -1231,6 +1146,187 @@ var startSlave = function(config, afterStartFn)
1231
1146
  });
1232
1147
  };
1233
1148
 
1149
+ var createHttpServer = function(app, done)
1150
+ {
1151
+ // create the server (either HTTP or HTTPS)
1152
+ var httpServer = null;
1153
+
1154
+ if (process.configuration.https)
1155
+ {
1156
+ if (app)
1157
+ {
1158
+ // configure helmet to support auto-upgrade of http->https
1159
+ app.use(helmet());
1160
+ }
1161
+
1162
+ // create https server
1163
+ httpServer = https.createServer(process.configuration.https, app);
1164
+ }
1165
+ else
1166
+ {
1167
+ // legacy
1168
+ httpServer = http.Server(app);
1169
+ }
1170
+
1171
+ // request timeout
1172
+ var requestTimeout = 30000; // 30 seconds
1173
+ if (process.configuration && process.configuration.timeout)
1174
+ {
1175
+ requestTimeout = process.configuration.timeout;
1176
+ }
1177
+ httpServer.setTimeout(requestTimeout);
1178
+
1179
+ // socket
1180
+ httpServer.on("connection", function (socket) {
1181
+ socket.setNoDelay(true);
1182
+ });
1183
+
1184
+ done(null, httpServer);
1185
+ }
1186
+
1187
+ var configureServer = function(config, app, httpServer, configureServerFinishedFn)
1188
+ {
1189
+ var io = httpServer.io;
1190
+ if (io)
1191
+ {
1192
+ //io.set('transports', config.socketTransports);
1193
+ io.use(function (socket, next) {
1194
+
1195
+ // console.log("New socket being initialized");
1196
+
1197
+ // attach _log function
1198
+ socket._log = function (text) {
1199
+
1200
+ var host = socket.handshake.headers.host;
1201
+ if (socket.handshake.headers["x-forwarded-host"])
1202
+ {
1203
+ host = socket.handshake.headers["x-forwarded-host"];
1204
+ }
1205
+
1206
+ var d = new Date();
1207
+ var dateString = d.toDateString();
1208
+ var timeString = d.toTimeString();
1209
+
1210
+ // gray color
1211
+ var grayColor = "\x1b[90m";
1212
+
1213
+ // final color
1214
+ var finalColor = "\x1b[0m";
1215
+
1216
+ if (process.env.CLOUDCMS_APPSERVER_MODE === "production")
1217
+ {
1218
+ grayColor = "";
1219
+ finalColor = "";
1220
+ }
1221
+
1222
+ var message = '';
1223
+ message += grayColor + '<socket> ';
1224
+ message += grayColor + '[' + dateString + ' ' + timeString + '] ';
1225
+ message += grayColor + host + ' ';
1226
+ message += grayColor + text + '';
1227
+ message += finalColor;
1228
+
1229
+ console.log(message);
1230
+ };
1231
+ /*
1232
+ socket.on("connect", function () {
1233
+ console.log("Socket connect()");
1234
+ });
1235
+ */
1236
+ /*
1237
+ socket.on("disconnect", function () {
1238
+ var message = "Socket disconnected";
1239
+ if (socket && socket.host)
1240
+ {
1241
+ message += ", host=" + socket.host;
1242
+ }
1243
+ if (socket && socket.gitana && socket.gitana.application && socket.gitana.application())
1244
+ {
1245
+ message += ", application=" + socket.gitana.application().title;
1246
+ }
1247
+ console.log(message);
1248
+ });
1249
+ */
1250
+
1251
+ // APPLY CUSTOM SOCKET.IO CONFIG
1252
+ runFunctions(config.socketFunctions, [socket], function (err) {
1253
+
1254
+ require("../middleware/awareness/awareness").initSocketIO(io, function() {
1255
+ next();
1256
+ });
1257
+
1258
+ // INSIGHT SERVER
1259
+ // if (config.insight && config.insight.enabled)
1260
+ // {
1261
+ // console.log("Init Insight to Socket");
1262
+
1263
+ // require("../insight/insight").init(socket, function () {
1264
+ // next();
1265
+ // });
1266
+ // }
1267
+ // else
1268
+ // {
1269
+ // next();
1270
+ // }
1271
+ });
1272
+
1273
+ });
1274
+ }
1275
+
1276
+ // SET INITIAL VALUE FOR SERVER TIMESTAMP
1277
+ process.env.CLOUDCMS_APPSERVER_TIMESTAMP = new Date().getTime();
1278
+
1279
+ // DUST
1280
+ runFunctions(config.dustFunctions, [app, duster.getDust()], function (err) {
1281
+
1282
+ // APPLY SERVER BEFORE START FUNCTIONS
1283
+ runFunctions(config.beforeFunctions, [app], function (err) {
1284
+
1285
+ // AFTER SERVER START
1286
+ runFunctions(config.afterFunctions, [app], function (err) {
1287
+
1288
+ function cleanup() {
1289
+
1290
+ if (cluster.isMaster)
1291
+ {
1292
+ console.log("");
1293
+ console.log("");
1294
+
1295
+ console.log("Cloud CMS Module shutting down");
1296
+
1297
+ // close server connections as cleanly as we can
1298
+ console.log(" -> Closing server connections");
1299
+ }
1300
+
1301
+ try
1302
+ {
1303
+ httpServer.close();
1304
+ }
1305
+ catch (e)
1306
+ {
1307
+ console.log("Server.close produced error: " + JSON.stringify(e));
1308
+ }
1309
+
1310
+ if (cluster.isMaster)
1311
+ {
1312
+ console.log("");
1313
+ }
1314
+
1315
+ // tell the process to exit
1316
+ process.exit();
1317
+ }
1318
+
1319
+ // listen for kill or interrupt so that we can shut down cleanly
1320
+ process.on('SIGINT', cleanup);
1321
+ process.on('SIGTERM', cleanup);
1322
+
1323
+ configureServerFinishedFn();
1324
+ });
1325
+ });
1326
+ });
1327
+ };
1328
+
1329
+
1234
1330
 
1235
1331
  ////////////////////////////////////////////////////////////////////////////
1236
1332
  //