cloudcms-server 0.9.263 → 0.9.267
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/middleware/authentication/adapters/session.js +11 -8
- package/middleware/authentication/authentication.js +28 -16
- package/middleware/authentication/authenticators/default.js +5 -2
- package/middleware/authentication/authenticators/session.js +5 -2
- package/middleware/authorization/authorization.js +11 -8
- package/package.json +1 -1
- package/server/index.js +413 -403
- package/temp/clusterlock/index.js +0 -2
|
@@ -9,15 +9,18 @@ class SessionAdapter extends AbstractAdapter
|
|
|
9
9
|
|
|
10
10
|
identify(req, callback)
|
|
11
11
|
{
|
|
12
|
-
if (req.session
|
|
12
|
+
if (req.session)
|
|
13
13
|
{
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
if (req.session._auth_profile)
|
|
15
|
+
{
|
|
16
|
+
var properties = {
|
|
17
|
+
"token": req.session._auth_profile.unique_name,
|
|
18
|
+
"trusted": true,
|
|
19
|
+
"profile": req.session._auth_profile
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
return callback(null, properties);
|
|
23
|
+
}
|
|
21
24
|
}
|
|
22
25
|
|
|
23
26
|
return super.identify(req, callback);
|
|
@@ -436,15 +436,21 @@ exports = module.exports = function()
|
|
|
436
436
|
}
|
|
437
437
|
else
|
|
438
438
|
{
|
|
439
|
-
req.session.
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
439
|
+
return req.session.reload(function() {
|
|
440
|
+
|
|
441
|
+
req.session.registration_strategy_id = strategyId;
|
|
442
|
+
req.session.registration_user_object = userObject;
|
|
443
|
+
req.session.registration_user_identifier = userIdentifier;
|
|
444
|
+
req.session.registration_groups_array = groupsArray;
|
|
445
|
+
req.session.registration_mandatory_groups_array = mandatoryGroupsArray;
|
|
446
|
+
req.session.registration_token = info.token;
|
|
447
|
+
req.session.registration_refresh_token = info.refresh_token;
|
|
448
|
+
|
|
449
|
+
req.session.save(function() {
|
|
450
|
+
res.redirect(registrationRedirectUrl);
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
});
|
|
448
454
|
}
|
|
449
455
|
});
|
|
450
456
|
}
|
|
@@ -765,13 +771,19 @@ exports = module.exports = function()
|
|
|
765
771
|
}
|
|
766
772
|
else
|
|
767
773
|
{
|
|
768
|
-
req.session.
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
774
|
+
return req.session.reload(function() {
|
|
775
|
+
|
|
776
|
+
req.session.registration_strategy_id = strategyId;
|
|
777
|
+
req.session.registration_user_object = properties.user_object;
|
|
778
|
+
req.session.registration_user_identifier = properties.user_identifier;
|
|
779
|
+
req.session.registration_token = properties.token;
|
|
780
|
+
req.session.registration_refresh_token = properties.refresh_token;
|
|
781
|
+
|
|
782
|
+
req.session.save(function() {
|
|
783
|
+
res.redirect(registrationRedirect);
|
|
784
|
+
});
|
|
785
|
+
|
|
786
|
+
});
|
|
775
787
|
}
|
|
776
788
|
}
|
|
777
789
|
|
|
@@ -15,8 +15,11 @@ class DefaultAuthenticator extends AbstractAuthenticator
|
|
|
15
15
|
{
|
|
16
16
|
return req.logIn(gitanaUser, function() {
|
|
17
17
|
|
|
18
|
-
if (req.session
|
|
19
|
-
|
|
18
|
+
if (req.session)
|
|
19
|
+
{
|
|
20
|
+
return req.session.save(function() {
|
|
21
|
+
callback();
|
|
22
|
+
});
|
|
20
23
|
}
|
|
21
24
|
|
|
22
25
|
callback();
|
|
@@ -25,8 +25,11 @@ class SessionAuthenticator extends DefaultAuthenticator
|
|
|
25
25
|
|
|
26
26
|
req.user = gitanaUser;
|
|
27
27
|
|
|
28
|
-
if (req.session
|
|
29
|
-
|
|
28
|
+
if (req.session)
|
|
29
|
+
{
|
|
30
|
+
return req.session.save(function() {
|
|
31
|
+
callback();
|
|
32
|
+
});
|
|
30
33
|
}
|
|
31
34
|
|
|
32
35
|
callback();
|
|
@@ -41,17 +41,20 @@ exports = module.exports = function()
|
|
|
41
41
|
}
|
|
42
42
|
*/
|
|
43
43
|
|
|
44
|
-
if (pathRequiresAuthorization)
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
res.redirect("/login");
|
|
50
|
-
}
|
|
44
|
+
if (!pathRequiresAuthorization)
|
|
45
|
+
{
|
|
46
|
+
return next();
|
|
51
47
|
}
|
|
52
|
-
|
|
48
|
+
|
|
49
|
+
if (req.session && req.session.requestContext)
|
|
50
|
+
{
|
|
53
51
|
next();
|
|
54
52
|
}
|
|
53
|
+
else
|
|
54
|
+
{
|
|
55
|
+
res.redirect("/login");
|
|
56
|
+
}
|
|
57
|
+
|
|
55
58
|
});
|
|
56
59
|
};
|
|
57
60
|
|
package/package.json
CHANGED
package/server/index.js
CHANGED
|
@@ -698,443 +698,453 @@ var _start = function(overrides, callback) {
|
|
|
698
698
|
});
|
|
699
699
|
};
|
|
700
700
|
|
|
701
|
-
var
|
|
701
|
+
var initSession = function(initDone)
|
|
702
702
|
{
|
|
703
|
-
|
|
704
|
-
|
|
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
|
+
};
|
|
705
720
|
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
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")
|
|
709
726
|
{
|
|
710
|
-
|
|
727
|
+
var options = {};
|
|
728
|
+
if (process.configuration.session.ttl)
|
|
711
729
|
{
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
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);
|
|
715
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
|
+
};
|
|
716
766
|
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
};
|
|
722
|
-
|
|
723
|
-
if (process.configuration.session.type === "file")
|
|
724
|
-
{
|
|
725
|
-
var options = {};
|
|
726
|
-
if (process.configuration.session.ttl)
|
|
727
|
-
{
|
|
728
|
-
options.ttl = process.configuration.session.ttl;
|
|
729
|
-
}
|
|
730
|
-
if (process.configuration.session.reapInterval)
|
|
731
|
-
{
|
|
732
|
-
options.reapInterval = process.configuration.session.reapInterval;
|
|
733
|
-
}
|
|
734
|
-
// session file store
|
|
735
|
-
var SessionFileStore = require('session-file-store')(session);
|
|
736
|
-
sessionConfig.store = new SessionFileStore(options);
|
|
737
|
-
}
|
|
738
|
-
else if (process.configuration.session.type === "redis")
|
|
739
|
-
{
|
|
740
|
-
(async function() {
|
|
741
|
-
var redisOptions = redisHelper.redisOptions();
|
|
742
|
-
redisHelper.createAndConnect(redisOptions, function(err, redisClient) {
|
|
767
|
+
var startServer = function(config, startServerFinishedFn)
|
|
768
|
+
{
|
|
769
|
+
var app = express();
|
|
770
|
+
app.disable('x-powered-by');
|
|
743
771
|
|
|
744
|
-
|
|
745
|
-
console.error(err);
|
|
746
|
-
}
|
|
747
|
-
else
|
|
748
|
-
{
|
|
749
|
-
var RedisStore = connectRedis(session);
|
|
750
|
-
sessionConfig.store = new RedisStore({ client: redisClient });
|
|
751
|
-
}
|
|
752
|
-
});
|
|
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
|
-
}
|
|
772
|
+
initSession(function(err, initializedSession) {
|
|
764
773
|
|
|
765
|
-
|
|
774
|
+
if (err) {
|
|
775
|
+
throw err;
|
|
766
776
|
}
|
|
767
|
-
|
|
777
|
+
|
|
778
|
+
// global temp directory
|
|
779
|
+
util.createTempDirectory(function(err, tempDirectory) {
|
|
780
|
+
process.env.CLOUDCMS_TEMPDIR_PATH = tempDirectory;
|
|
768
781
|
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
app.set('port', process.env.PORT);
|
|
789
|
-
app.set('views', process.env.CLOUDCMS_APPSERVER_BASE_PATH + "/views");
|
|
790
|
-
|
|
791
|
-
if (config.viewEngine === "dust")
|
|
792
|
-
{
|
|
793
|
-
var cons = require('consolidate');
|
|
794
|
-
|
|
795
|
-
app.set('view engine', 'html');
|
|
796
|
-
app.set('view engine', 'dust');
|
|
797
|
-
app.engine('html', cons.dust);
|
|
798
|
-
app.engine('dust', cons.dust);
|
|
799
|
-
}
|
|
800
|
-
else if (config.viewEngine === "handlebars" || config.viewEngine === "hbs")
|
|
801
|
-
{
|
|
802
|
-
var hbs = require('hbs');
|
|
803
|
-
|
|
804
|
-
app.set('view engine', 'html');
|
|
805
|
-
app.set('view engine', 'hbs');
|
|
806
|
-
app.engine('html', hbs.__express);
|
|
807
|
-
app.engine('hbs', hbs.__express);
|
|
808
|
-
}
|
|
809
|
-
|
|
810
|
-
////////////////////////////////////////////////////////////////////////////
|
|
811
|
-
//
|
|
812
|
-
// VIRTUAL SUPPORT
|
|
813
|
-
//
|
|
814
|
-
// Configure NodeJS to load virtual driver and configure for virtual descriptors
|
|
815
|
-
// ahead of anything else running.
|
|
816
|
-
//
|
|
817
|
-
////////////////////////////////////////////////////////////////////////////
|
|
818
|
-
|
|
819
|
-
// custom morgan logger
|
|
820
|
-
morgan(function (tokens, req, res) {
|
|
821
|
-
|
|
822
|
-
var status = res.statusCode;
|
|
823
|
-
var len = parseInt(res.getHeader('Content-Length'), 10);
|
|
824
|
-
var host = req.domainHost;
|
|
825
|
-
if (req.virtualHost) {
|
|
826
|
-
host = req.virtualHost;
|
|
827
|
-
}
|
|
828
|
-
|
|
829
|
-
len = isNaN(len) ? '0b' : len = bytes(len);
|
|
830
|
-
|
|
831
|
-
var d = new Date();
|
|
832
|
-
var dateString = d.toDateString();
|
|
833
|
-
var timeString = d.toTimeString();
|
|
834
|
-
|
|
835
|
-
// gray color
|
|
836
|
-
var grayColor = "\x1b[90m";
|
|
837
|
-
|
|
838
|
-
// status color
|
|
839
|
-
var color = 32;
|
|
840
|
-
if (status >= 500) {
|
|
841
|
-
color = 31;
|
|
842
|
-
}
|
|
843
|
-
else if (status >= 400) {
|
|
844
|
-
color = 33;
|
|
845
|
-
}
|
|
846
|
-
else if (status >= 300) {
|
|
847
|
-
color = 36;
|
|
848
|
-
}
|
|
849
|
-
var statusColor = "\x1b[" + color + "m";
|
|
850
|
-
|
|
851
|
-
// final color
|
|
852
|
-
var finalColor = "\x1b[0m";
|
|
853
|
-
|
|
854
|
-
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")
|
|
855
801
|
{
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
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);
|
|
859
808
|
}
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
message += grayColor + '"' + req.method + ' ';
|
|
869
|
-
message += grayColor + req.originalUrl + '" ';
|
|
870
|
-
message += grayColor + len + ' ';
|
|
871
|
-
message += finalColor;
|
|
872
|
-
|
|
873
|
-
return message;
|
|
874
|
-
});
|
|
875
|
-
|
|
876
|
-
/*
|
|
877
|
-
// debug headers being set
|
|
878
|
-
app.use(function(req, res, next) {
|
|
879
|
-
var setHeader = res.setHeader;
|
|
880
|
-
res.setHeader = function(a,b) {
|
|
881
|
-
console.trace("Writing header: " + a + " = " + b);
|
|
882
|
-
setHeader.call(this, a,b);
|
|
883
|
-
};
|
|
884
|
-
next();
|
|
885
|
-
});
|
|
886
|
-
*/
|
|
887
|
-
|
|
888
|
-
// middleware which blocks requests when we're too busy
|
|
889
|
-
app.use(function(req, res, next) {
|
|
890
|
-
if (toobusy()) {
|
|
891
|
-
res.status(503).send("The web application is too busy to serve this request. Please try again.");
|
|
892
|
-
} else {
|
|
893
|
-
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);
|
|
894
817
|
}
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
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;
|
|
912
883
|
});
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
var host = req.domainHost;
|
|
923
|
-
if (req.virtualHost)
|
|
924
|
-
{
|
|
925
|
-
host = req.virtualHost;
|
|
926
|
-
}
|
|
927
|
-
|
|
928
|
-
var timestamp = moment(new Date()).format("MM/DD/YYYY HH:mm:ss Z");
|
|
929
|
-
var grayColor = "\x1b[90m";
|
|
930
|
-
var finalColor = "\x1b[0m";
|
|
931
|
-
|
|
932
|
-
// in production, don't use colors
|
|
933
|
-
if (process.env.CLOUDCMS_APPSERVER_MODE === "production")
|
|
934
|
-
{
|
|
935
|
-
grayColor = "";
|
|
936
|
-
finalColor = "";
|
|
937
|
-
}
|
|
938
|
-
|
|
939
|
-
var message = '';
|
|
940
|
-
message += grayColor + '<' + req.id + '> ';
|
|
941
|
-
if (cluster.worker && cluster.worker.id)
|
|
942
|
-
{
|
|
943
|
-
message += grayColor + '(' + cluster.worker.id + ') ';
|
|
944
|
-
}
|
|
945
|
-
message += grayColor + '[' + timestamp + '] ';
|
|
946
|
-
message += grayColor + host + ' ';
|
|
947
|
-
message += grayColor + text + '';
|
|
948
|
-
message += finalColor;
|
|
949
|
-
|
|
950
|
-
/*
|
|
951
|
-
if (warn)
|
|
952
|
-
{
|
|
953
|
-
message = "\r\n**** SLOW RESPONSE ****\r\n" + message + "\r\n";
|
|
954
|
-
}
|
|
955
|
-
*/
|
|
956
|
-
|
|
957
|
-
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);
|
|
958
892
|
};
|
|
959
|
-
|
|
960
893
|
next();
|
|
961
894
|
});
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
var warn = false;
|
|
971
|
-
if (time > 1000)
|
|
972
|
-
{
|
|
973
|
-
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();
|
|
974
903
|
}
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
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)
|
|
985
981
|
{
|
|
986
|
-
|
|
982
|
+
warn = true;
|
|
987
983
|
}
|
|
988
|
-
|
|
984
|
+
|
|
985
|
+
var requestPath = req.originalPath;
|
|
986
|
+
if (requestPath)
|
|
989
987
|
{
|
|
990
|
-
|
|
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
|
+
}
|
|
991
1001
|
}
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
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
|
+
});
|
|
1043
1053
|
});
|
|
1044
1054
|
});
|
|
1045
1055
|
});
|
|
1056
|
+
|
|
1046
1057
|
});
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
if (initializedSession)
|
|
1051
|
-
{
|
|
1052
|
-
app.use(initializedSession);
|
|
1053
|
-
app.use(flash());
|
|
1054
|
-
}
|
|
1055
|
-
|
|
1056
|
-
// this is the same as calling
|
|
1057
|
-
// app.use(passport.initialize());
|
|
1058
|
-
// except we create a new passport each time and store on request to support multitenancy
|
|
1059
|
-
app.use(function(req, res, next) {
|
|
1060
|
-
|
|
1061
|
-
var passport = new Passport();
|
|
1062
|
-
passport._key = "passport-" + req.virtualHost;
|
|
1063
|
-
|
|
1064
|
-
req._passport = {};
|
|
1065
|
-
req._passport.instance = passport;
|
|
1066
|
-
|
|
1067
|
-
if (req.session && req.session[passport._key])
|
|
1058
|
+
|
|
1059
|
+
if (initializedSession)
|
|
1068
1060
|
{
|
|
1069
|
-
|
|
1070
|
-
|
|
1061
|
+
app.use(initializedSession);
|
|
1062
|
+
app.use(flash());
|
|
1071
1063
|
}
|
|
1072
|
-
|
|
1073
|
-
//
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
// passport - serialize and deserialize
|
|
1077
|
-
req.passport.serializeUser(function(user, done) {
|
|
1078
|
-
done(null, user);
|
|
1079
|
-
});
|
|
1080
|
-
req.passport.deserializeUser(function(user, done) {
|
|
1081
|
-
done(null, user);
|
|
1082
|
-
});
|
|
1083
|
-
|
|
1084
|
-
next();
|
|
1085
|
-
});
|
|
1086
|
-
|
|
1087
|
-
// passport session
|
|
1088
|
-
if (initializedSession)
|
|
1089
|
-
{
|
|
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
|
|
1090
1068
|
app.use(function(req, res, next) {
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
main.interceptors(app, true);
|
|
1100
|
-
|
|
1101
|
-
//app.use(app.router);
|
|
1102
|
-
|
|
1103
|
-
// healthcheck middleware
|
|
1104
|
-
main.healthcheck(app);
|
|
1105
|
-
|
|
1106
|
-
// APPLY CUSTOM ROUTES
|
|
1107
|
-
runFunctions(config.routeFunctions, [app], function (err) {
|
|
1108
|
-
|
|
1109
|
-
// configure cloudcms app server handlers
|
|
1110
|
-
main.handlers(app, true);
|
|
1111
|
-
|
|
1112
|
-
// register error functions
|
|
1113
|
-
runFunctions(config.errorFunctions, [app], function (err) {
|
|
1114
|
-
|
|
1115
|
-
// APPLY CUSTOM CONFIGURE FUNCTIONS
|
|
1116
|
-
var allConfigureFunctions = [];
|
|
1117
|
-
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])
|
|
1118
1077
|
{
|
|
1119
|
-
|
|
1120
|
-
|
|
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)
|
|
1121
1127
|
{
|
|
1122
|
-
|
|
1128
|
+
var functions = config.configureFunctions[env];
|
|
1129
|
+
if (functions)
|
|
1123
1130
|
{
|
|
1124
|
-
|
|
1131
|
+
for (var i = 0; i < functions.length; i++)
|
|
1132
|
+
{
|
|
1133
|
+
allConfigureFunctions.push(functions[i]);
|
|
1134
|
+
}
|
|
1125
1135
|
}
|
|
1126
1136
|
}
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
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
|
+
});
|
|
1138
1148
|
});
|
|
1139
1149
|
});
|
|
1140
1150
|
});
|
|
@@ -158,7 +158,6 @@ process.on('message', _workerIncomingMessagesHandler);
|
|
|
158
158
|
|
|
159
159
|
var _lock = function(key, fn) {
|
|
160
160
|
|
|
161
|
-
console.log("z1: " + key);
|
|
162
161
|
// notify master that we have something waiting to run for this lock
|
|
163
162
|
_sendMessageToMaster({
|
|
164
163
|
"type": "claim",
|
|
@@ -166,7 +165,6 @@ var _lock = function(key, fn) {
|
|
|
166
165
|
"key": key
|
|
167
166
|
},
|
|
168
167
|
"callback": function(ticket) {
|
|
169
|
-
console.log("z2: " + ticket);
|
|
170
168
|
|
|
171
169
|
fn.call(null, function(afterReleaseCallback) {
|
|
172
170
|
|