cloudcms-server 0.9.248 → 0.9.253

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/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  },
7
7
  "name": "cloudcms-server",
8
8
  "description": "Cloud CMS Application Server Module",
9
- "version": "0.9.248",
9
+ "version": "0.9.253",
10
10
  "repository": {
11
11
  "type": "git",
12
12
  "url": "git://github.com/gitana/cloudcms-server.git"
@@ -36,9 +36,10 @@
36
36
  "express-session": "^1.16.2",
37
37
  "express-useragent": "^1.0.13",
38
38
  "extend-with-super": "^2.0.0",
39
- "gitana": "^1.0.315",
39
+ "gitana": "^1.0.322",
40
40
  "handlebars": "^4.4.2",
41
41
  "hbs": "^4.0.5",
42
+ "helmet": "^4.6.0",
42
43
  "http-proxy": "^1.18.1",
43
44
  "json5": "^1.0.1",
44
45
  "jsonwebtoken": "^8.5.1",
package/server/index.js CHANGED
@@ -16,6 +16,9 @@ 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
 
@@ -37,6 +40,8 @@ var duster = require("../duster/index");
37
40
 
38
41
  var coreHelpers = require("../duster/helpers/core/index");
39
42
 
43
+ var helmet = require("helmet");
44
+
40
45
  var toobusy = require("toobusy-js");
41
46
  toobusy.maxLag(500); // 500 ms lag in event queue, quite high but usable for now
42
47
  toobusy.interval(250);
@@ -585,6 +590,51 @@ var startSlave = function(config, afterStartFn)
585
590
  if (!process.env.CLOUDCMS_STANDALONE_HOST) {
586
591
  process.env.CLOUDCMS_STANDALONE_HOST = "local";
587
592
  }
593
+
594
+
595
+ // auto-configuration for HTTPS
596
+ if (!process.configuration.https) {
597
+ process.configuration.https = {};
598
+ }
599
+ if (process.env.CLOUDCMS_HTTPS) {
600
+ process.configuration.https = JSON.parse(process.env.CLOUDCMS_HTTPS);
601
+ }
602
+ if (process.env.CLOUDCMS_HTTPS_KEY_FILEPATH) {
603
+ process.configuration.https.key = fs.readFileSync(process.env.CLOUDCMS_HTTPS_KEY_FILEPATH);
604
+ }
605
+ if (process.env.CLOUDCMS_HTTPS_CERT_FILEPATH) {
606
+ process.configuration.https.cert = fs.readFileSync(process.env.CLOUDCMS_HTTPS_CERT_FILEPATH);
607
+ }
608
+ if (process.env.CLOUDCMS_HTTPS_PFX_FILEPATH) {
609
+ process.configuration.https.pfx = fs.readFileSync(process.env.CLOUDCMS_HTTPS_PFX_FILEPATH);
610
+ }
611
+ if (process.env.CLOUDCMS_HTTPS_PASSPHRASE) {
612
+ process.configuration.https.passphrase = process.env.CLOUDCMS_HTTPS_PASSPHRASE;
613
+ }
614
+ if (process.env.CLOUDCMS_HTTPS_REQUEST_CERT === "true") {
615
+ process.configuration.https.requestCert = true;
616
+ }
617
+ if (process.env.CLOUDCMS_HTTPS_CA_FILEPATH) {
618
+ process.configuration.https.ca = [ fs.readFileSync(process.env.CLOUDCMS_HTTPS_CA_FILEPATH) ];
619
+ }
620
+
621
+ // if https config is empty, remove it
622
+ if (Object.keys(process.configuration.https).length === 0) {
623
+ delete process.configuration.https;
624
+ }
625
+
626
+
627
+ // auto configuration of session store
628
+ if (!process.configuration.session) {
629
+ process.configuration.session = {};
630
+ }
631
+ if (process.env.CLOUDCMS_SESSION_TYPE) {
632
+ process.configuration.session.enabled = true;
633
+ process.configuration.session.type = process.env.CLOUDCMS_SESSION_TYPE;
634
+ }
635
+ if (process.env.CLOUDCMS_SESSION_SECRET) {
636
+ process.configuration.session.secret = process.env.CLOUDCMS_SESSION_SECRET;
637
+ }
588
638
 
589
639
  // session store
590
640
  var initializedSession = null;
@@ -618,6 +668,28 @@ var startSlave = function(config, afterStartFn)
618
668
  var SessionFileStore = require('session-file-store')(session);
619
669
  sessionConfig.store = new SessionFileStore(options);
620
670
  }
671
+ else if (process.configuration.session.type === "redis")
672
+ {
673
+ var redisPort = process.env.CLOUDCMS_REDIS_PORT;
674
+ var redisHost = process.env.CLOUDCMS_REDIS_ENDPOINT;
675
+
676
+ if (!redisPort)
677
+ {
678
+ console.error("Cannot configure session for Redis storage because CLOUDCMS_REDIS_PORT is not defined");
679
+ }
680
+ else if (!redisHost)
681
+ {
682
+ console.error("Cannot configure session for Redis storage because CLOUDCMS_REDIS_ENDPOINT is not defined");
683
+ }
684
+ else
685
+ {
686
+ var redisOptions = {};
687
+ var redisClient = redis.createClient(redisPort, redisHost, redisOptions);
688
+
689
+ var RedisStore = connectRedis(session);
690
+ sessionConfig.store = new RedisStore({ client: redisClient });
691
+ }
692
+ }
621
693
  else if (process.configuration.session.type === "memory" || !process.configuration.session.type)
622
694
  {
623
695
  var options = {};
@@ -1045,8 +1117,17 @@ var startSlave = function(config, afterStartFn)
1045
1117
  ////////////////////////////////////////////////////////////////////////////
1046
1118
 
1047
1119
 
1048
- // CORE OBJECTS
1049
- var server = http.Server(app);
1120
+ // create the server (either HTTP or HTTPS)
1121
+ var server = null;
1122
+ if (process.configuration.https) {
1123
+ // configure helmet to support auto-upgrade of http->https
1124
+ app.use(helmet());
1125
+ // create https server
1126
+ server = https.createServer(process.configuration.https, app);
1127
+ } else {
1128
+ // legacy
1129
+ server = http.Server(app);
1130
+ }
1050
1131
 
1051
1132
  // request timeout
1052
1133
  var requestTimeout = 30000; // 30 seconds
@@ -69,6 +69,11 @@ server.report(function(callback) {
69
69
  console.log("Hosts Directory: " + process.env.CLOUDCMS_HOSTS_PATH);
70
70
  console.log("LaunchPad Mode: " + process.env.CLOUDCMS_LAUNCHPAD_SETUP);
71
71
  console.log("Max Files Detected: " + process.env.CLOUDCMS_MAX_FILES);
72
+ console.log("Session Type: " + process.configuration.session.type);
73
+
74
+ if (process.configuration.https) {
75
+ console.log("Server is configured to use HTTPS");
76
+ }
72
77
 
73
78
  console.log("");
74
79