cloudcms-server 0.9.261 → 0.9.264

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/server/index.js CHANGED
@@ -311,9 +311,7 @@ var SETTINGS = {
311
311
  //"reapInterval": -1
312
312
  },
313
313
  "awareness": {
314
- "enabled": false,
315
- "type": "memory",
316
- "config": {}
314
+ "enabled": false
317
315
  },
318
316
  "graphql": {
319
317
  "enabled": true,
@@ -700,443 +698,453 @@ var _start = function(overrides, callback) {
700
698
  });
701
699
  };
702
700
 
703
- var startServer = function(config, startServerFinishedFn)
701
+ var initSession = function(initDone)
704
702
  {
705
- var app = express();
706
- app.disable('x-powered-by');
703
+ if (!process.configuration.session) {
704
+ return initDone();
705
+ }
706
+ if (!process.configuration.session.enabled) {
707
+ return initDone();
708
+ }
709
+
710
+ var sessionSecret = process.configuration.session.secret;
711
+ if (!sessionSecret) {
712
+ sessionSecret = "secret";
713
+ }
714
+
715
+ var sessionConfig = {
716
+ secret: sessionSecret,
717
+ resave: false,
718
+ saveUninitialized: false
719
+ };
707
720
 
708
- // session store
709
- var initializedSession = null;
710
- if (process.configuration.session)
721
+ if (process.configuration.session.type) {
722
+ process.configuration.session.type = process.configuration.session.type.toLowerCase();
723
+ }
724
+
725
+ if (process.configuration.session.type === "file")
711
726
  {
712
- if (process.configuration.session.enabled)
727
+ var options = {};
728
+ if (process.configuration.session.ttl)
713
729
  {
714
- var sessionSecret = process.configuration.session.secret;
715
- if (!sessionSecret) {
716
- sessionSecret = "secret";
730
+ options.ttl = process.configuration.session.ttl;
731
+ }
732
+ if (process.configuration.session.reapInterval)
733
+ {
734
+ options.reapInterval = process.configuration.session.reapInterval;
735
+ }
736
+ // session file store
737
+ var SessionFileStore = require('session-file-store')(session);
738
+ sessionConfig.store = new SessionFileStore(options);
739
+ return initDone(null, session(sessionConfig));
740
+ }
741
+ else if (process.configuration.session.type === "redis")
742
+ {
743
+ var redisOptions = redisHelper.redisOptions();
744
+ return redisHelper.createAndConnect(redisOptions, function(err, redisClient) {
745
+
746
+ if (err) {
747
+ return initDone(err);
717
748
  }
749
+
750
+ var RedisStore = connectRedis(session);
751
+ sessionConfig.store = new RedisStore({ client: redisClient });
752
+ initDone(null, session(sessionConfig));
753
+ });
754
+ }
755
+ else if (process.configuration.session.type === "memory" || !process.configuration.session.type)
756
+ {
757
+ var options = {};
758
+ options.checkPeriod = 86400000; // prune expired entries every 24h
759
+
760
+ // session memory store
761
+ var MemoryStore = require('memorystore')(session);
762
+ sessionConfig.store = new MemoryStore(options);
763
+ return initDone(null, session(sessionConfig));
764
+ }
765
+ };
718
766
 
719
- var sessionConfig = {
720
- secret: sessionSecret,
721
- resave: false,
722
- saveUninitialized: false
723
- };
724
-
725
- if (process.configuration.session.type === "file")
726
- {
727
- var options = {};
728
- if (process.configuration.session.ttl)
729
- {
730
- options.ttl = process.configuration.session.ttl;
731
- }
732
- if (process.configuration.session.reapInterval)
733
- {
734
- options.reapInterval = process.configuration.session.reapInterval;
735
- }
736
- // session file store
737
- var SessionFileStore = require('session-file-store')(session);
738
- sessionConfig.store = new SessionFileStore(options);
739
- }
740
- else if (process.configuration.session.type === "redis")
741
- {
742
- (async function() {
743
- var redisOptions = redisHelper.redisOptions();
744
- redisHelper.createAndConnect(redisOptions, function(err, redisClient) {
767
+ var startServer = function(config, startServerFinishedFn)
768
+ {
769
+ var app = express();
770
+ app.disable('x-powered-by');
745
771
 
746
- if (err) {
747
- console.error(err);
748
- }
749
- else
750
- {
751
- var RedisStore = connectRedis(session);
752
- sessionConfig.store = new RedisStore({ client: redisClient });
753
- }
754
- });
755
- })();
756
- }
757
- else if (process.configuration.session.type === "memory" || !process.configuration.session.type)
758
- {
759
- var options = {};
760
- options.checkPeriod = 86400000; // prune expired entries every 24h
761
-
762
- // session memory store
763
- var MemoryStore = require('memorystore')(session);
764
- sessionConfig.store = new MemoryStore(options);
765
- }
772
+ initSession(function(err, initializedSession) {
766
773
 
767
- initializedSession = session(sessionConfig);
774
+ if (err) {
775
+ throw err;
768
776
  }
769
- }
777
+
778
+ // global temp directory
779
+ util.createTempDirectory(function(err, tempDirectory) {
780
+ process.env.CLOUDCMS_TEMPDIR_PATH = tempDirectory;
770
781
 
771
- // global temp directory
772
- util.createTempDirectory(function(err, tempDirectory) {
773
- process.env.CLOUDCMS_TEMPDIR_PATH = tempDirectory;
774
-
775
- // global service starts
776
- main.init(app, function (err) {
777
-
778
- app.enable('strict routing');
779
-
780
- ////////////////////////////////////////////////////////////////////////////
781
- //
782
- // BASE CONFIGURATION
783
- //
784
- // Configures NodeJS app server using dustjs templating engine
785
- // Runs on port 3000 by default
786
- //
787
- ////////////////////////////////////////////////////////////////////////////
788
-
789
- // all environments
790
- app.set('port', process.env.PORT);
791
- app.set('views', process.env.CLOUDCMS_APPSERVER_BASE_PATH + "/views");
792
-
793
- if (config.viewEngine === "dust")
794
- {
795
- var cons = require('consolidate');
796
-
797
- app.set('view engine', 'html');
798
- app.set('view engine', 'dust');
799
- app.engine('html', cons.dust);
800
- app.engine('dust', cons.dust);
801
- }
802
- else if (config.viewEngine === "handlebars" || config.viewEngine === "hbs")
803
- {
804
- var hbs = require('hbs');
805
-
806
- app.set('view engine', 'html');
807
- app.set('view engine', 'hbs');
808
- app.engine('html', hbs.__express);
809
- app.engine('hbs', hbs.__express);
810
- }
811
-
812
- ////////////////////////////////////////////////////////////////////////////
813
- //
814
- // VIRTUAL SUPPORT
815
- //
816
- // Configure NodeJS to load virtual driver and configure for virtual descriptors
817
- // ahead of anything else running.
818
- //
819
- ////////////////////////////////////////////////////////////////////////////
820
-
821
- // custom morgan logger
822
- morgan(function (tokens, req, res) {
823
-
824
- var status = res.statusCode;
825
- var len = parseInt(res.getHeader('Content-Length'), 10);
826
- var host = req.domainHost;
827
- if (req.virtualHost) {
828
- host = req.virtualHost;
829
- }
830
-
831
- len = isNaN(len) ? '0b' : len = bytes(len);
832
-
833
- var d = new Date();
834
- var dateString = d.toDateString();
835
- var timeString = d.toTimeString();
836
-
837
- // gray color
838
- var grayColor = "\x1b[90m";
839
-
840
- // status color
841
- var color = 32;
842
- if (status >= 500) {
843
- color = 31;
844
- }
845
- else if (status >= 400) {
846
- color = 33;
847
- }
848
- else if (status >= 300) {
849
- color = 36;
850
- }
851
- var statusColor = "\x1b[" + color + "m";
852
-
853
- // final color
854
- var finalColor = "\x1b[0m";
855
-
856
- if (process.env.CLOUDCMS_APPSERVER_MODE === "production")
782
+ // global service starts
783
+ main.init(app, function (err) {
784
+
785
+ app.enable('strict routing');
786
+
787
+ ////////////////////////////////////////////////////////////////////////////
788
+ //
789
+ // BASE CONFIGURATION
790
+ //
791
+ // Configures NodeJS app server using dustjs templating engine
792
+ // Runs on port 3000 by default
793
+ //
794
+ ////////////////////////////////////////////////////////////////////////////
795
+
796
+ // all environments
797
+ app.set('port', process.env.PORT);
798
+ app.set('views', process.env.CLOUDCMS_APPSERVER_BASE_PATH + "/views");
799
+
800
+ if (config.viewEngine === "dust")
857
801
  {
858
- grayColor = "";
859
- statusColor = "";
860
- finalColor = "";
802
+ var cons = require('consolidate');
803
+
804
+ app.set('view engine', 'html');
805
+ app.set('view engine', 'dust');
806
+ app.engine('html', cons.dust);
807
+ app.engine('dust', cons.dust);
861
808
  }
862
-
863
- var message = '';
864
- message += grayColor + '<' + req.id + '> ';
865
- message += grayColor + '[' + dateString + ' ' + timeString + '] ';
866
- message += grayColor + host + ' ';
867
- //message += grayColor + '(' + req.ip + ') ';
868
- message += statusColor + res.statusCode + ' ';
869
- message += statusColor + (new Date - req._startTime) + ' ms ';
870
- message += grayColor + '"' + req.method + ' ';
871
- message += grayColor + req.originalUrl + '" ';
872
- message += grayColor + len + ' ';
873
- message += finalColor;
874
-
875
- return message;
876
- });
877
-
878
- /*
879
- // debug headers being set
880
- app.use(function(req, res, next) {
881
- var setHeader = res.setHeader;
882
- res.setHeader = function(a,b) {
883
- console.trace("Writing header: " + a + " = " + b);
884
- setHeader.call(this, a,b);
885
- };
886
- next();
887
- });
888
- */
889
-
890
- // middleware which blocks requests when we're too busy
891
- app.use(function(req, res, next) {
892
- if (toobusy()) {
893
- res.status(503).send("The web application is too busy to serve this request. Please try again.");
894
- } else {
895
- next();
809
+ else if (config.viewEngine === "handlebars" || config.viewEngine === "hbs")
810
+ {
811
+ var hbs = require('hbs');
812
+
813
+ app.set('view engine', 'html');
814
+ app.set('view engine', 'hbs');
815
+ app.engine('html', hbs.__express);
816
+ app.engine('hbs', hbs.__express);
896
817
  }
897
- });
898
-
899
- // add req.id re
900
- app.use(function (req, res, next) {
901
- requestCounter++;
902
- req.id = requestCounter;
903
- next();
904
- });
905
-
906
- // APPLY CUSTOM INIT FUNCTIONS
907
- runFunctions(config.initFunctions, [app], function (err) {
908
-
909
- // retain originalUrl and originalPath since these can get modified along the way
910
- app.use(function (req, res, next) {
911
- req.originalUrl = req.url;
912
- req.originalPath = req.path;
913
- next();
818
+
819
+ ////////////////////////////////////////////////////////////////////////////
820
+ //
821
+ // VIRTUAL SUPPORT
822
+ //
823
+ // Configure NodeJS to load virtual driver and configure for virtual descriptors
824
+ // ahead of anything else running.
825
+ //
826
+ ////////////////////////////////////////////////////////////////////////////
827
+
828
+ // custom morgan logger
829
+ morgan(function (tokens, req, res) {
830
+
831
+ var status = res.statusCode;
832
+ var len = parseInt(res.getHeader('Content-Length'), 10);
833
+ var host = req.domainHost;
834
+ if (req.virtualHost) {
835
+ host = req.virtualHost;
836
+ }
837
+
838
+ len = isNaN(len) ? '0b' : len = bytes(len);
839
+
840
+ var d = new Date();
841
+ var dateString = d.toDateString();
842
+ var timeString = d.toTimeString();
843
+
844
+ // gray color
845
+ var grayColor = "\x1b[90m";
846
+
847
+ // status color
848
+ var color = 32;
849
+ if (status >= 500) {
850
+ color = 31;
851
+ }
852
+ else if (status >= 400) {
853
+ color = 33;
854
+ }
855
+ else if (status >= 300) {
856
+ color = 36;
857
+ }
858
+ var statusColor = "\x1b[" + color + "m";
859
+
860
+ // final color
861
+ var finalColor = "\x1b[0m";
862
+
863
+ if (process.env.CLOUDCMS_APPSERVER_MODE === "production")
864
+ {
865
+ grayColor = "";
866
+ statusColor = "";
867
+ finalColor = "";
868
+ }
869
+
870
+ var message = '';
871
+ message += grayColor + '<' + req.id + '> ';
872
+ message += grayColor + '[' + dateString + ' ' + timeString + '] ';
873
+ message += grayColor + host + ' ';
874
+ //message += grayColor + '(' + req.ip + ') ';
875
+ message += statusColor + res.statusCode + ' ';
876
+ message += statusColor + (new Date - req._startTime) + ' ms ';
877
+ message += grayColor + '"' + req.method + ' ';
878
+ message += grayColor + req.originalUrl + '" ';
879
+ message += grayColor + len + ' ';
880
+ message += finalColor;
881
+
882
+ return message;
914
883
  });
915
-
916
- // req.param method
917
- app.use(requestParam);
918
-
919
- // add req.log function
920
- app.use(function (req, res, next) {
921
-
922
- req._log = req.log = function (text/*, warn*/) {
923
-
924
- var host = req.domainHost;
925
- if (req.virtualHost)
926
- {
927
- host = req.virtualHost;
928
- }
929
-
930
- var timestamp = moment(new Date()).format("MM/DD/YYYY HH:mm:ss Z");
931
- var grayColor = "\x1b[90m";
932
- var finalColor = "\x1b[0m";
933
-
934
- // in production, don't use colors
935
- if (process.env.CLOUDCMS_APPSERVER_MODE === "production")
936
- {
937
- grayColor = "";
938
- finalColor = "";
939
- }
940
-
941
- var message = '';
942
- message += grayColor + '<' + req.id + '> ';
943
- if (cluster.worker && cluster.worker.id)
944
- {
945
- message += grayColor + '(' + cluster.worker.id + ') ';
946
- }
947
- message += grayColor + '[' + timestamp + '] ';
948
- message += grayColor + host + ' ';
949
- message += grayColor + text + '';
950
- message += finalColor;
951
-
952
- /*
953
- if (warn)
954
- {
955
- message = "\r\n**** SLOW RESPONSE ****\r\n" + message + "\r\n";
956
- }
957
- */
958
-
959
- console.log(message);
884
+
885
+ /*
886
+ // debug headers being set
887
+ app.use(function(req, res, next) {
888
+ var setHeader = res.setHeader;
889
+ res.setHeader = function(a,b) {
890
+ console.trace("Writing header: " + a + " = " + b);
891
+ setHeader.call(this, a,b);
960
892
  };
961
-
962
893
  next();
963
894
  });
964
-
965
- // common interceptors and config
966
- main.common1(app);
967
-
968
- // general logging of requests
969
- // gather statistics on response time
970
- app.use(responseTime(function (req, res, time) {
971
-
972
- var warn = false;
973
- if (time > 1000)
974
- {
975
- warn = true;
895
+ */
896
+
897
+ // middleware which blocks requests when we're too busy
898
+ app.use(function(req, res, next) {
899
+ if (toobusy()) {
900
+ res.status(503).send("The web application is too busy to serve this request. Please try again.");
901
+ } else {
902
+ next();
976
903
  }
977
-
978
- var requestPath = req.originalPath;
979
- if (requestPath)
980
- {
981
- var filter = false;
982
- if (requestPath.indexOf("/login") > -1)
983
- {
984
- filter = true;
985
- }
986
- if (requestPath.indexOf("/token") > -1)
904
+ });
905
+
906
+ // add req.id re
907
+ app.use(function (req, res, next) {
908
+ requestCounter++;
909
+ req.id = requestCounter;
910
+ next();
911
+ });
912
+
913
+ // APPLY CUSTOM INIT FUNCTIONS
914
+ runFunctions(config.initFunctions, [app], function (err) {
915
+
916
+ // retain originalUrl and originalPath since these can get modified along the way
917
+ app.use(function (req, res, next) {
918
+ req.originalUrl = req.url;
919
+ req.originalPath = req.path;
920
+ next();
921
+ });
922
+
923
+ // req.param method
924
+ app.use(requestParam);
925
+
926
+ // add req.log function
927
+ app.use(function (req, res, next) {
928
+
929
+ req._log = req.log = function (text/*, warn*/) {
930
+
931
+ var host = req.domainHost;
932
+ if (req.virtualHost)
933
+ {
934
+ host = req.virtualHost;
935
+ }
936
+
937
+ var timestamp = moment(new Date()).format("MM/DD/YYYY HH:mm:ss Z");
938
+ var grayColor = "\x1b[90m";
939
+ var finalColor = "\x1b[0m";
940
+
941
+ // in production, don't use colors
942
+ if (process.env.CLOUDCMS_APPSERVER_MODE === "production")
943
+ {
944
+ grayColor = "";
945
+ finalColor = "";
946
+ }
947
+
948
+ var message = '';
949
+ message += grayColor + '<' + req.id + '> ';
950
+ if (cluster.worker && cluster.worker.id)
951
+ {
952
+ message += grayColor + '(' + cluster.worker.id + ') ';
953
+ }
954
+ message += grayColor + '[' + timestamp + '] ';
955
+ message += grayColor + host + ' ';
956
+ message += grayColor + text + '';
957
+ message += finalColor;
958
+
959
+ /*
960
+ if (warn)
961
+ {
962
+ message = "\r\n**** SLOW RESPONSE ****\r\n" + message + "\r\n";
963
+ }
964
+ */
965
+
966
+ console.log(message);
967
+ };
968
+
969
+ next();
970
+ });
971
+
972
+ // common interceptors and config
973
+ main.common1(app);
974
+
975
+ // general logging of requests
976
+ // gather statistics on response time
977
+ app.use(responseTime(function (req, res, time) {
978
+
979
+ var warn = false;
980
+ if (time > 1000)
987
981
  {
988
- filter = true;
982
+ warn = true;
989
983
  }
990
- if (filter)
984
+
985
+ var requestPath = req.originalPath;
986
+ if (requestPath)
991
987
  {
992
- requestPath = util.stripQueryStringFromUrl(requestPath);
988
+ var filter = false;
989
+ if (requestPath.indexOf("/login") > -1)
990
+ {
991
+ filter = true;
992
+ }
993
+ if (requestPath.indexOf("/token") > -1)
994
+ {
995
+ filter = true;
996
+ }
997
+ if (filter)
998
+ {
999
+ requestPath = util.stripQueryStringFromUrl(requestPath);
1000
+ }
993
1001
  }
994
- }
995
-
996
- req.log(req.method + " " + requestPath + " [" + res.statusCode + "] (" + time.toFixed(2) + " ms)", warn);
997
- }));
998
-
999
- // set up CORS allowances
1000
- // this lets CORS requests float through the proxy
1001
- app.use(main.ensureCORS());
1002
-
1003
- // set up default security headers
1004
- app.use(main.ensureHeaders());
1005
-
1006
- // common interceptors and config
1007
- main.common2(app);
1008
-
1009
- // APPLY CUSTOM DRIVER FUNCTIONS
1010
- runFunctions(config.driverFunctions, [app], function(err) {
1011
-
1012
- // binds gitana driver into place
1013
- main.common3(app);
1014
-
1015
- // parse cookies
1016
- app.use(cookieParser());
1017
-
1018
- // cloudcms things need to run here
1019
- main.common4(app, true);
1020
-
1021
- // APPLY CUSTOM FILTER FUNCTIONS
1022
- runFunctions(config.filterFunctions, [app], function (err) {
1023
-
1024
- // PATH BASED PERFORMANCE CACHING
1025
- main.perf1(app);
1026
-
1027
- // proxy - anything that goes to /proxy is handled here early and nothing processes afterwards
1028
- main.proxy(app);
1029
-
1030
- // MIMETYPE BASED PERFORMANCE CACHING
1031
- main.perf2(app);
1032
-
1033
- // DEVELOPMENT BASED PERFORMANCE CACHING
1034
- main.perf3(app);
1035
-
1036
- // standard body parsing + a special cloud cms body parser that makes a last ditch effort for anything
1037
- // that might be JSON (regardless of content type)
1038
- app.use(function (req, res, next) {
1039
-
1040
- multipart(process.configuration.bodyParsers.multipart || {})(req, res, function (err) {
1041
- bodyParser.json(process.configuration.bodyParsers.json || {})(req, res, function (err) {
1042
- bodyParser.urlencoded(process.configuration.bodyParsers.urlencoded || {})(req, res, function (err) {
1043
- main.bodyParser()(req, res, function (err) {
1044
- next(err);
1002
+
1003
+ req.log(req.method + " " + requestPath + " [" + res.statusCode + "] (" + time.toFixed(2) + " ms)", warn);
1004
+ }));
1005
+
1006
+ // set up CORS allowances
1007
+ // this lets CORS requests float through the proxy
1008
+ app.use(main.ensureCORS());
1009
+
1010
+ // set up default security headers
1011
+ app.use(main.ensureHeaders());
1012
+
1013
+ // common interceptors and config
1014
+ main.common2(app);
1015
+
1016
+ // APPLY CUSTOM DRIVER FUNCTIONS
1017
+ runFunctions(config.driverFunctions, [app], function(err) {
1018
+
1019
+ // binds gitana driver into place
1020
+ main.common3(app);
1021
+
1022
+ // parse cookies
1023
+ app.use(cookieParser());
1024
+
1025
+ // cloudcms things need to run here
1026
+ main.common4(app, true);
1027
+
1028
+ // APPLY CUSTOM FILTER FUNCTIONS
1029
+ runFunctions(config.filterFunctions, [app], function (err) {
1030
+
1031
+ // PATH BASED PERFORMANCE CACHING
1032
+ main.perf1(app);
1033
+
1034
+ // proxy - anything that goes to /proxy is handled here early and nothing processes afterwards
1035
+ main.proxy(app);
1036
+
1037
+ // MIMETYPE BASED PERFORMANCE CACHING
1038
+ main.perf2(app);
1039
+
1040
+ // DEVELOPMENT BASED PERFORMANCE CACHING
1041
+ main.perf3(app);
1042
+
1043
+ // standard body parsing + a special cloud cms body parser that makes a last ditch effort for anything
1044
+ // that might be JSON (regardless of content type)
1045
+ app.use(function (req, res, next) {
1046
+
1047
+ multipart(process.configuration.bodyParsers.multipart || {})(req, res, function (err) {
1048
+ bodyParser.json(process.configuration.bodyParsers.json || {})(req, res, function (err) {
1049
+ bodyParser.urlencoded(process.configuration.bodyParsers.urlencoded || {})(req, res, function (err) {
1050
+ main.bodyParser()(req, res, function (err) {
1051
+ next(err);
1052
+ });
1045
1053
  });
1046
1054
  });
1047
1055
  });
1056
+
1048
1057
  });
1049
-
1050
- });
1051
-
1052
- if (initializedSession)
1053
- {
1054
- app.use(initializedSession);
1055
- app.use(flash());
1056
- }
1057
-
1058
- // this is the same as calling
1059
- // app.use(passport.initialize());
1060
- // except we create a new passport each time and store on request to support multitenancy
1061
- app.use(function(req, res, next) {
1062
-
1063
- var passport = new Passport();
1064
- passport._key = "passport-" + req.virtualHost;
1065
-
1066
- req._passport = {};
1067
- req._passport.instance = passport;
1068
-
1069
- if (req.session && req.session[passport._key])
1058
+
1059
+ if (initializedSession)
1070
1060
  {
1071
- // load data from existing session
1072
- req._passport.session = req.session[passport._key];
1061
+ app.use(initializedSession);
1062
+ app.use(flash());
1073
1063
  }
1074
-
1075
- // add this in
1076
- req.passport = req._passport.instance;
1077
-
1078
- // passport - serialize and deserialize
1079
- req.passport.serializeUser(function(user, done) {
1080
- done(null, user);
1081
- });
1082
- req.passport.deserializeUser(function(user, done) {
1083
- done(null, user);
1084
- });
1085
-
1086
- next();
1087
- });
1088
-
1089
- // passport session
1090
- if (initializedSession)
1091
- {
1064
+
1065
+ // this is the same as calling
1066
+ // app.use(passport.initialize());
1067
+ // except we create a new passport each time and store on request to support multitenancy
1092
1068
  app.use(function(req, res, next) {
1093
- req.passport.session()(req, res, next);
1094
- });
1095
- }
1096
-
1097
- // welcome files
1098
- main.welcome(app);
1099
-
1100
- // configure cloudcms app server command handing
1101
- main.interceptors(app, true);
1102
-
1103
- //app.use(app.router);
1104
-
1105
- // healthcheck middleware
1106
- main.healthcheck(app);
1107
-
1108
- // APPLY CUSTOM ROUTES
1109
- runFunctions(config.routeFunctions, [app], function (err) {
1110
-
1111
- // configure cloudcms app server handlers
1112
- main.handlers(app, true);
1113
-
1114
- // register error functions
1115
- runFunctions(config.errorFunctions, [app], function (err) {
1116
-
1117
- // APPLY CUSTOM CONFIGURE FUNCTIONS
1118
- var allConfigureFunctions = [];
1119
- for (var env in config.configureFunctions)
1069
+
1070
+ var passport = new Passport();
1071
+ passport._key = "passport-" + req.virtualHost;
1072
+
1073
+ req._passport = {};
1074
+ req._passport.instance = passport;
1075
+
1076
+ if (req.session && req.session[passport._key])
1120
1077
  {
1121
- var functions = config.configureFunctions[env];
1122
- if (functions)
1078
+ // load data from existing session
1079
+ req._passport.session = req.session[passport._key];
1080
+ }
1081
+
1082
+ // add this in
1083
+ req.passport = req._passport.instance;
1084
+
1085
+ // passport - serialize and deserialize
1086
+ req.passport.serializeUser(function(user, done) {
1087
+ done(null, user);
1088
+ });
1089
+ req.passport.deserializeUser(function(user, done) {
1090
+ done(null, user);
1091
+ });
1092
+
1093
+ next();
1094
+ });
1095
+
1096
+ // passport session
1097
+ if (initializedSession)
1098
+ {
1099
+ app.use(function(req, res, next) {
1100
+ req.passport.session()(req, res, next);
1101
+ });
1102
+ }
1103
+
1104
+ // welcome files
1105
+ main.welcome(app);
1106
+
1107
+ // configure cloudcms app server command handing
1108
+ main.interceptors(app, true);
1109
+
1110
+ //app.use(app.router);
1111
+
1112
+ // healthcheck middleware
1113
+ main.healthcheck(app);
1114
+
1115
+ // APPLY CUSTOM ROUTES
1116
+ runFunctions(config.routeFunctions, [app], function (err) {
1117
+
1118
+ // configure cloudcms app server handlers
1119
+ main.handlers(app, true);
1120
+
1121
+ // register error functions
1122
+ runFunctions(config.errorFunctions, [app], function (err) {
1123
+
1124
+ // APPLY CUSTOM CONFIGURE FUNCTIONS
1125
+ var allConfigureFunctions = [];
1126
+ for (var env in config.configureFunctions)
1123
1127
  {
1124
- for (var i = 0; i < functions.length; i++)
1128
+ var functions = config.configureFunctions[env];
1129
+ if (functions)
1125
1130
  {
1126
- allConfigureFunctions.push(functions[i]);
1131
+ for (var i = 0; i < functions.length; i++)
1132
+ {
1133
+ allConfigureFunctions.push(functions[i]);
1134
+ }
1127
1135
  }
1128
1136
  }
1129
- }
1130
- runFunctions(allConfigureFunctions, [app], function (err) {
1131
-
1132
- // create the server (either HTTP or HTTPS)
1133
- createHttpServer(app, function(err, httpServer) {
1134
-
1135
- if (err) {
1136
- return startServerFinishedFn(err);
1137
- }
1138
-
1139
- startServerFinishedFn(null, app, httpServer);
1137
+ runFunctions(allConfigureFunctions, [app], function (err) {
1138
+
1139
+ // create the server (either HTTP or HTTPS)
1140
+ createHttpServer(app, function(err, httpServer) {
1141
+
1142
+ if (err) {
1143
+ return startServerFinishedFn(err);
1144
+ }
1145
+
1146
+ startServerFinishedFn(null, app, httpServer);
1147
+ });
1140
1148
  });
1141
1149
  });
1142
1150
  });
@@ -1253,7 +1261,7 @@ var configureServer = function(config, app, httpServer, configureServerFinishedF
1253
1261
  // APPLY CUSTOM SOCKET.IO CONFIG
1254
1262
  runFunctions(config.socketFunctions, [socket], function (err) {
1255
1263
 
1256
- require("../middleware/awareness/awareness").initSocketIO(function() {
1264
+ require("../middleware/awareness/awareness").initSocketIO(io, function() {
1257
1265
  next();
1258
1266
  });
1259
1267