cloudcms-server 3.2.326 → 3.2.328
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/index.js +69 -0
- package/middleware/virtual-config/virtual-config.js +31 -0
- package/package.json +1 -1
- package/server/index.js +27 -43
- package/util/auth.js +1 -0
package/index.js
CHANGED
|
@@ -29,6 +29,33 @@ process.logInfo = process.log = function(text, level)
|
|
|
29
29
|
systemLogger.log(text, level);
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
+
var debugLog = process.debugLog = function(req, message)
|
|
33
|
+
{
|
|
34
|
+
var text = "[" + req.id + "] URL: " + req.url;
|
|
35
|
+
// if (req.headers)
|
|
36
|
+
// {
|
|
37
|
+
// text += ", HEADERS: " + JSON.stringify(req.headers);
|
|
38
|
+
// }
|
|
39
|
+
if (req.query)
|
|
40
|
+
{
|
|
41
|
+
text += ", QUERY: " + JSON.stringify(req.query);
|
|
42
|
+
}
|
|
43
|
+
text += ", MESSAGE: " + message;
|
|
44
|
+
|
|
45
|
+
console.log(text);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
var debugMiddleware = process.debugMiddleware = function(message)
|
|
49
|
+
{
|
|
50
|
+
return function(req, res, next)
|
|
51
|
+
{
|
|
52
|
+
debugLog(req, message);
|
|
53
|
+
|
|
54
|
+
next();
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
|
|
32
59
|
|
|
33
60
|
// by default, set up Gitana driver so that it limits to five concurrent HTTP requests back to Cloud CMS API at at time
|
|
34
61
|
var Gitana = require("gitana");
|
|
@@ -306,43 +333,82 @@ exports = module.exports = function()
|
|
|
306
333
|
|
|
307
334
|
r.common1 = function(app)
|
|
308
335
|
{
|
|
336
|
+
// DEBUG
|
|
337
|
+
app.use(debugMiddleware("DEBUG x1"));
|
|
338
|
+
|
|
309
339
|
// app config interceptor
|
|
310
340
|
applyApplicationConfiguration(app);
|
|
311
341
|
|
|
342
|
+
// DEBUG
|
|
343
|
+
app.use(debugMiddleware("DEBUG x2"));
|
|
344
|
+
|
|
312
345
|
// sets locale onto the request
|
|
313
346
|
app.use(locale.localeInterceptor());
|
|
314
347
|
|
|
348
|
+
// DEBUG
|
|
349
|
+
app.use(debugMiddleware("DEBUG x3"));
|
|
350
|
+
|
|
315
351
|
// sets host onto the request
|
|
316
352
|
app.use(host.hostInterceptor());
|
|
353
|
+
|
|
354
|
+
// DEBUG
|
|
355
|
+
app.use(debugMiddleware("DEBUG x4"));
|
|
317
356
|
};
|
|
318
357
|
|
|
319
358
|
r.common2 = function(app)
|
|
320
359
|
{
|
|
360
|
+
// DEBUG
|
|
361
|
+
app.use(debugMiddleware("DEBUG y1"));
|
|
362
|
+
|
|
321
363
|
// bind stores into the request
|
|
322
364
|
app.use(storeService.storesInterceptor());
|
|
323
365
|
|
|
366
|
+
// DEBUG
|
|
367
|
+
app.use(debugMiddleware("DEBUG y2"));
|
|
368
|
+
|
|
324
369
|
// puts req.descriptor into the request and req.virtualFiles = true
|
|
325
370
|
app.use(virtualFiles.interceptor());
|
|
326
371
|
|
|
372
|
+
// DEBUG
|
|
373
|
+
app.use(debugMiddleware("DEBUG y3"));
|
|
374
|
+
|
|
327
375
|
// puts req.runtime into the request
|
|
328
376
|
app.use(runtime.interceptor());
|
|
329
377
|
|
|
378
|
+
// DEBUG
|
|
379
|
+
app.use(debugMiddleware("DEBUG y4"));
|
|
380
|
+
|
|
330
381
|
// if virtual hosting is enabled, loads "gitana.json" from cloud cms and places it into rootStore
|
|
331
382
|
// for convenience, also populates req.gitanaConfig
|
|
332
383
|
app.use(virtualConfig.interceptor());
|
|
333
384
|
|
|
385
|
+
// DEBUG
|
|
386
|
+
app.use(debugMiddleware("DEBUG y5"));
|
|
387
|
+
|
|
334
388
|
// general method for finding "gitana.json" in root store and populating req.gitanaConfig
|
|
335
389
|
app.use(driverConfig.interceptor());
|
|
390
|
+
|
|
391
|
+
// DEBUG
|
|
392
|
+
app.use(debugMiddleware("DEBUG y6"));
|
|
336
393
|
};
|
|
337
394
|
|
|
338
395
|
r.common3 = function(app)
|
|
339
396
|
{
|
|
397
|
+
// DEBUG
|
|
398
|
+
app.use(debugMiddleware("DEBUG z1"));
|
|
399
|
+
|
|
340
400
|
// binds "req.gitana" into the request for the loaded "req.gitanaConfig"
|
|
341
401
|
app.use(driver.driverInterceptor());
|
|
402
|
+
|
|
403
|
+
// DEBUG
|
|
404
|
+
app.use(debugMiddleware("DEBUG z2"));
|
|
342
405
|
};
|
|
343
406
|
|
|
344
407
|
r.common4 = function(app, includeCloudCMS)
|
|
345
408
|
{
|
|
409
|
+
// DEBUG
|
|
410
|
+
app.use(debugMiddleware("DEBUG v1"));
|
|
411
|
+
|
|
346
412
|
var configuration = app.configuration;
|
|
347
413
|
|
|
348
414
|
if (includeCloudCMS)
|
|
@@ -375,6 +441,9 @@ exports = module.exports = function()
|
|
|
375
441
|
|
|
376
442
|
// graphql
|
|
377
443
|
app.use(graphql.interceptor());
|
|
444
|
+
|
|
445
|
+
// DEBUG
|
|
446
|
+
app.use(debugMiddleware("DEBUG v2"));
|
|
378
447
|
};
|
|
379
448
|
|
|
380
449
|
r.perf1 = function(app)
|
|
@@ -2,6 +2,8 @@ var util = require("../../util/util");
|
|
|
2
2
|
|
|
3
3
|
var workQueueFactory = require("../../util/workqueue");
|
|
4
4
|
|
|
5
|
+
var debugLog = process.debugLog;
|
|
6
|
+
|
|
5
7
|
/**
|
|
6
8
|
* Retrieves virtual driver configuration for hosts from Cloud CMS.
|
|
7
9
|
*
|
|
@@ -355,8 +357,11 @@ exports = module.exports = function()
|
|
|
355
357
|
|
|
356
358
|
var completionFunction = function (err, gitanaConfig, doesNotExist)
|
|
357
359
|
{
|
|
360
|
+
debugLog(req, "g20");
|
|
358
361
|
if (doesNotExist)
|
|
359
362
|
{
|
|
363
|
+
debugLog(req, "g21");
|
|
364
|
+
|
|
360
365
|
// console.log("BLOCK, method: " + req.method + ", url: " + req.url);
|
|
361
366
|
// if (req.headers)
|
|
362
367
|
// {
|
|
@@ -373,6 +378,8 @@ exports = module.exports = function()
|
|
|
373
378
|
return res.end(JSON.stringify({"error": true, "message": "Bad Request."}));
|
|
374
379
|
}
|
|
375
380
|
|
|
381
|
+
debugLog(req, "g22");
|
|
382
|
+
|
|
376
383
|
if (err)
|
|
377
384
|
{
|
|
378
385
|
if (err.message)
|
|
@@ -380,11 +387,15 @@ exports = module.exports = function()
|
|
|
380
387
|
req.log(err.message);
|
|
381
388
|
}
|
|
382
389
|
|
|
390
|
+
debugLog(req, "g23: " + err);
|
|
391
|
+
|
|
383
392
|
return next();
|
|
384
393
|
}
|
|
385
394
|
|
|
386
395
|
if (gitanaConfig)
|
|
387
396
|
{
|
|
397
|
+
debugLog(req, "g24: " + JSON.stringify(gitanaConfig, null, 2));
|
|
398
|
+
|
|
388
399
|
// store config
|
|
389
400
|
req.gitanaConfig = gitanaConfig;
|
|
390
401
|
|
|
@@ -392,11 +403,18 @@ exports = module.exports = function()
|
|
|
392
403
|
req.gitanaLocal = false;
|
|
393
404
|
}
|
|
394
405
|
|
|
406
|
+
debugLog(req, "g30");
|
|
407
|
+
|
|
395
408
|
next();
|
|
396
409
|
};
|
|
397
410
|
|
|
411
|
+
debugLog(req, "g1: " + req.virtualHost);
|
|
412
|
+
|
|
398
413
|
process.driverConfigCache.read(req.virtualHost, function(err, cachedValue)
|
|
399
414
|
{
|
|
415
|
+
debugLog(req, "g2: " + err);
|
|
416
|
+
debugLog(req, "g3: " + cachedValue);
|
|
417
|
+
|
|
400
418
|
if (process.env.NULL_DRIVER_CACHE === "true") {
|
|
401
419
|
cachedValue = null;
|
|
402
420
|
}
|
|
@@ -405,20 +423,29 @@ exports = module.exports = function()
|
|
|
405
423
|
{
|
|
406
424
|
if (cachedValue === SENTINEL_NOT_FOUND_VALUE)
|
|
407
425
|
{
|
|
426
|
+
debugLog(req, "g4");
|
|
427
|
+
|
|
408
428
|
// null means there verifiably isn't anything on disk (null used as sentinel marker)
|
|
409
429
|
completionFunction(null, null, true);
|
|
410
430
|
}
|
|
411
431
|
else
|
|
412
432
|
{
|
|
433
|
+
debugLog(req, "g5");
|
|
434
|
+
|
|
413
435
|
// we have something in cache
|
|
414
436
|
completionFunction(null, cachedValue.config);
|
|
415
437
|
}
|
|
416
438
|
}
|
|
417
439
|
else
|
|
418
440
|
{
|
|
441
|
+
debugLog(req, "g6");
|
|
442
|
+
|
|
419
443
|
// try to load from disk
|
|
420
444
|
acquireGitanaJson(req.virtualHost, req.rootStore, req.log, function (err, gitanaConfig, doesNotExist)
|
|
421
445
|
{
|
|
446
|
+
debugLog(req, "g7: " + err);
|
|
447
|
+
debugLog(req, "g8: " + gitanaConfig);
|
|
448
|
+
|
|
422
449
|
if (err && !doesNotExist)
|
|
423
450
|
{
|
|
424
451
|
return completionFunction(err);
|
|
@@ -426,6 +453,8 @@ exports = module.exports = function()
|
|
|
426
453
|
|
|
427
454
|
if (gitanaConfig)
|
|
428
455
|
{
|
|
456
|
+
debugLog(req, "g9: " + JSON.stringify(gitanaConfig, null, 2));
|
|
457
|
+
|
|
429
458
|
return process.driverConfigCache.write(req.virtualHost, {
|
|
430
459
|
"config": gitanaConfig
|
|
431
460
|
}, function (err) {
|
|
@@ -433,6 +462,8 @@ exports = module.exports = function()
|
|
|
433
462
|
});
|
|
434
463
|
}
|
|
435
464
|
|
|
465
|
+
debugLog(req, "g10: " + req.virtualHost);
|
|
466
|
+
|
|
436
467
|
// mark with sentinel (30 minutes)
|
|
437
468
|
req.log("[BLACKLIST] Adding: " + req.virtualHost);
|
|
438
469
|
process.driverConfigCache.write(req.virtualHost, SENTINEL_NOT_FOUND_VALUE, BLACKLIST_TTL_SECONDS, function (err) {
|
package/package.json
CHANGED
package/server/index.js
CHANGED
|
@@ -729,6 +729,8 @@ var initSession = function(initDone)
|
|
|
729
729
|
}
|
|
730
730
|
};
|
|
731
731
|
|
|
732
|
+
var debugMiddleware = process.debugMiddleware;
|
|
733
|
+
|
|
732
734
|
var startServer = function(config, startServerFinishedFn)
|
|
733
735
|
{
|
|
734
736
|
var app = express();
|
|
@@ -898,10 +900,7 @@ var startServer = function(config, startServerFinishedFn)
|
|
|
898
900
|
});
|
|
899
901
|
|
|
900
902
|
// DEBUG
|
|
901
|
-
app.use(
|
|
902
|
-
console.log("[REQ: " + req.id + "] DEBUG 1");
|
|
903
|
-
next();
|
|
904
|
-
});
|
|
903
|
+
app.use(debugMiddleware("DEBUG 1"));
|
|
905
904
|
|
|
906
905
|
// APPLY CUSTOM INIT FUNCTIONS
|
|
907
906
|
runFunctions(config.initFunctions, [app], function (err) {
|
|
@@ -997,10 +996,7 @@ var startServer = function(config, startServerFinishedFn)
|
|
|
997
996
|
main.common1(app);
|
|
998
997
|
|
|
999
998
|
// DEBUG
|
|
1000
|
-
app.use(
|
|
1001
|
-
console.log("[REQ: " + req.id + "] DEBUG 2");
|
|
1002
|
-
next();
|
|
1003
|
-
});
|
|
999
|
+
app.use(debugMiddleware("DEBUG 2"));
|
|
1004
1000
|
|
|
1005
1001
|
// general logging of requests
|
|
1006
1002
|
// gather statistics on response time
|
|
@@ -1040,22 +1036,28 @@ var startServer = function(config, startServerFinishedFn)
|
|
|
1040
1036
|
|
|
1041
1037
|
req.log(m, warn);
|
|
1042
1038
|
}));
|
|
1043
|
-
|
|
1039
|
+
|
|
1040
|
+
// DEBUG
|
|
1041
|
+
app.use(debugMiddleware("DEBUG 2a"));
|
|
1042
|
+
|
|
1044
1043
|
// set up CORS allowances
|
|
1045
1044
|
// this lets CORS requests float through the proxy
|
|
1046
1045
|
app.use(main.ensureCORS());
|
|
1047
|
-
|
|
1046
|
+
|
|
1047
|
+
// DEBUG
|
|
1048
|
+
app.use(debugMiddleware("DEBUG 2b"));
|
|
1049
|
+
|
|
1048
1050
|
// set up default security headers
|
|
1049
1051
|
app.use(main.ensureHeaders());
|
|
1050
|
-
|
|
1052
|
+
|
|
1053
|
+
// DEBUG
|
|
1054
|
+
app.use(debugMiddleware("DEBUG 2c"));
|
|
1055
|
+
|
|
1051
1056
|
// common interceptors and config
|
|
1052
1057
|
main.common2(app);
|
|
1053
1058
|
|
|
1054
1059
|
// DEBUG
|
|
1055
|
-
app.use(
|
|
1056
|
-
console.log("[REQ: " + req.id + "] DEBUG 3");
|
|
1057
|
-
next();
|
|
1058
|
-
});
|
|
1060
|
+
app.use(debugMiddleware("DEBUG 3"));
|
|
1059
1061
|
|
|
1060
1062
|
// APPLY CUSTOM DRIVER FUNCTIONS
|
|
1061
1063
|
runFunctions(config.driverFunctions, [app], function(err) {
|
|
@@ -1070,10 +1072,7 @@ var startServer = function(config, startServerFinishedFn)
|
|
|
1070
1072
|
main.common4(app, true);
|
|
1071
1073
|
|
|
1072
1074
|
// DEBUG
|
|
1073
|
-
app.use(
|
|
1074
|
-
console.log("[REQ: " + req.id + "] DEBUG 4");
|
|
1075
|
-
next();
|
|
1076
|
-
});
|
|
1075
|
+
app.use(debugMiddleware("DEBUG 4"));
|
|
1077
1076
|
|
|
1078
1077
|
// APPLY CUSTOM FILTER FUNCTIONS
|
|
1079
1078
|
runFunctions(config.filterFunctions, [app], function (err) {
|
|
@@ -1091,10 +1090,7 @@ var startServer = function(config, startServerFinishedFn)
|
|
|
1091
1090
|
main.perf3(app);
|
|
1092
1091
|
|
|
1093
1092
|
// DEBUG
|
|
1094
|
-
app.use(
|
|
1095
|
-
console.log("[REQ: " + req.id + "] DEBUG 5");
|
|
1096
|
-
next();
|
|
1097
|
-
});
|
|
1093
|
+
app.use(debugMiddleware("DEBUG 5"));
|
|
1098
1094
|
|
|
1099
1095
|
// standard body parsing + a special cloud cms body parser that makes a last ditch effort for anything
|
|
1100
1096
|
// that might be JSON (regardless of content type)
|
|
@@ -1119,10 +1115,7 @@ var startServer = function(config, startServerFinishedFn)
|
|
|
1119
1115
|
}
|
|
1120
1116
|
|
|
1121
1117
|
// DEBUG
|
|
1122
|
-
app.use(
|
|
1123
|
-
console.log("[REQ: " + req.id + "] DEBUG 6");
|
|
1124
|
-
next();
|
|
1125
|
-
});
|
|
1118
|
+
app.use(debugMiddleware("DEBUG 6"));
|
|
1126
1119
|
|
|
1127
1120
|
// this is the same as calling
|
|
1128
1121
|
// app.use(passport.initialize());
|
|
@@ -1164,10 +1157,7 @@ var startServer = function(config, startServerFinishedFn)
|
|
|
1164
1157
|
}
|
|
1165
1158
|
|
|
1166
1159
|
// DEBUG
|
|
1167
|
-
app.use(
|
|
1168
|
-
console.log("[REQ: " + req.id + "] DEBUG 7");
|
|
1169
|
-
next();
|
|
1170
|
-
});
|
|
1160
|
+
app.use(debugMiddleware("DEBUG 7"));
|
|
1171
1161
|
|
|
1172
1162
|
// welcome files
|
|
1173
1163
|
main.welcome(app);
|
|
@@ -1181,28 +1171,19 @@ var startServer = function(config, startServerFinishedFn)
|
|
|
1181
1171
|
main.healthcheck(app);
|
|
1182
1172
|
|
|
1183
1173
|
// DEBUG
|
|
1184
|
-
app.use(
|
|
1185
|
-
console.log("[REQ: " + req.id + "] DEBUG 8");
|
|
1186
|
-
next();
|
|
1187
|
-
});
|
|
1174
|
+
app.use(debugMiddleware("DEBUG 8"));
|
|
1188
1175
|
|
|
1189
1176
|
// APPLY CUSTOM ROUTES
|
|
1190
1177
|
runFunctions(config.routeFunctions, [app], function (err) {
|
|
1191
1178
|
|
|
1192
1179
|
// DEBUG
|
|
1193
|
-
app.use(
|
|
1194
|
-
console.log("[REQ: " + req.id + "] DEBUG 9");
|
|
1195
|
-
next();
|
|
1196
|
-
});
|
|
1180
|
+
app.use(debugMiddleware("DEBUG 9"));
|
|
1197
1181
|
|
|
1198
1182
|
// configure cloudcms app server handlers
|
|
1199
1183
|
main.handlers(app, true);
|
|
1200
1184
|
|
|
1201
1185
|
// DEBUG
|
|
1202
|
-
app.use(
|
|
1203
|
-
console.log("[REQ: " + req.id + "] DEBUG 10");
|
|
1204
|
-
next();
|
|
1205
|
-
});
|
|
1186
|
+
app.use(debugMiddleware("DEBUG 10"));
|
|
1206
1187
|
|
|
1207
1188
|
// register error functions
|
|
1208
1189
|
runFunctions(config.errorFunctions, [app], function (err) {
|
|
@@ -1279,6 +1260,9 @@ var createHttpServer = function(app, done)
|
|
|
1279
1260
|
|
|
1280
1261
|
// socket
|
|
1281
1262
|
httpServer.on("connection", function (socket) {
|
|
1263
|
+
|
|
1264
|
+
console.log("[SOCKET CONNECTION] " + socket);
|
|
1265
|
+
|
|
1282
1266
|
socket.setNoDelay(true);
|
|
1283
1267
|
|
|
1284
1268
|
socket.setTimeout(requestTimeout, function(socket) {
|
package/util/auth.js
CHANGED