cloudcms-server 3.2.327 → 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 +18 -13
- package/middleware/virtual-config/virtual-config.js +31 -0
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -29,26 +29,31 @@ 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
|
+
|
|
32
48
|
var debugMiddleware = process.debugMiddleware = function(message)
|
|
33
49
|
{
|
|
34
50
|
return function(req, res, next)
|
|
35
51
|
{
|
|
36
|
-
|
|
37
|
-
// if (req.headers)
|
|
38
|
-
// {
|
|
39
|
-
// text += ", HEADERS: " + JSON.stringify(req.headers);
|
|
40
|
-
// }
|
|
41
|
-
if (req.query)
|
|
42
|
-
{
|
|
43
|
-
text += ", QUERY: " + JSON.stringify(req.query);
|
|
44
|
-
}
|
|
45
|
-
text += ", MESSAGE: " + message;
|
|
46
|
-
|
|
47
|
-
console.log(text);
|
|
52
|
+
debugLog(req, message);
|
|
48
53
|
|
|
49
54
|
next();
|
|
50
55
|
}
|
|
51
|
-
}
|
|
56
|
+
};
|
|
52
57
|
|
|
53
58
|
|
|
54
59
|
|
|
@@ -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) {
|