cloudcms-server 3.3.1-beta.1 → 3.3.1-beta.10
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/.last_command +7 -0
- package/broadcast/providers/redis.js +32 -57
- package/clients/nrp.js +117 -0
- package/clients/redis.js +48 -0
- package/duster/helpers/sample/nyt.js +5 -7
- package/framework/controllers.js +0 -1
- package/index.js +23 -13
- package/insight/insight.js +6 -9
- package/locks/providers/redis.js +29 -58
- package/middleware/admin/admin.js +4 -4
- package/middleware/awareness/awareness.js +4 -1
- package/middleware/awareness/plugins/editorial.js +41 -66
- package/middleware/awareness/plugins/resources.js +74 -0
- package/middleware/awareness/providers/redis.js +263 -237
- package/middleware/cache/providers/redis.js +134 -92
- package/middleware/config/config.js +41 -2
- package/middleware/deployment/deployment.js +19 -22
- package/middleware/form/form.js +18 -33
- package/middleware/modules/modules.js +64 -11
- package/middleware/proxy/proxy.js +1 -2
- package/middleware/stores/engines/s3.js +0 -2
- package/middleware/stores/stores.js +50 -6
- package/middleware/themes/themes.js +49 -0
- package/middleware/virtual-config/virtual-config.js +35 -39
- package/notifications/notifications.js +75 -2
- package/package.json +18 -19
- package/server/index.js +105 -24
- package/server/standalone.js +2 -0
- package/util/auth.js +2 -7
- package/util/cloudcms.js +19 -34
- package/util/proxy-factory.js +17 -7
- package/util/redis.js +113 -0
- package/util/renditions.js +6 -12
- package/util/request.js +117 -0
- package/util/util.js +23 -36
- package/web/socket.io/socket.io.js +4240 -2
- package/web/cms/ice.js +0 -109
- package/web/cms/preview.js +0 -106
package/util/request.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
var axios = require("axios");
|
|
2
|
+
|
|
3
|
+
var http = require("http");
|
|
4
|
+
var https = require("https");
|
|
5
|
+
|
|
6
|
+
var FormData = require("form-data");
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Incoming config:
|
|
10
|
+
*
|
|
11
|
+
* {
|
|
12
|
+
* "url": "",
|
|
13
|
+
* "method": "",
|
|
14
|
+
* "headers": {},
|
|
15
|
+
* "qs": {},
|
|
16
|
+
* "data": "" | {},
|
|
17
|
+
* "json": {}
|
|
18
|
+
* }
|
|
19
|
+
*
|
|
20
|
+
* Callback is (err, response).
|
|
21
|
+
*
|
|
22
|
+
* Where response is the Axios response object.
|
|
23
|
+
*
|
|
24
|
+
* @param config
|
|
25
|
+
* @param callback
|
|
26
|
+
*/
|
|
27
|
+
module.exports = function(config, callback)
|
|
28
|
+
{
|
|
29
|
+
// request config - https://github.com/request/request#requestoptions-callback
|
|
30
|
+
// axios config - https://www.npmjs.com/package/axios
|
|
31
|
+
|
|
32
|
+
var requestConfig = {};
|
|
33
|
+
requestConfig.url = config.uri || config.url;
|
|
34
|
+
requestConfig.method = config.method || "get";
|
|
35
|
+
requestConfig.headers = {};
|
|
36
|
+
|
|
37
|
+
if (!config) {
|
|
38
|
+
config = {};
|
|
39
|
+
}
|
|
40
|
+
if (!config.headers) {
|
|
41
|
+
config.headers = {};
|
|
42
|
+
}
|
|
43
|
+
for (var k in config.headers)
|
|
44
|
+
{
|
|
45
|
+
var v = config.headers[k];
|
|
46
|
+
if (v)
|
|
47
|
+
{
|
|
48
|
+
requestConfig.headers[k.trim().toLowerCase()] = v;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
// support for FormData headers
|
|
52
|
+
// copy form data headers
|
|
53
|
+
if (config.data && config.data.getHeaders)
|
|
54
|
+
{
|
|
55
|
+
var formDataHeaders = config.data.getHeaders();
|
|
56
|
+
for (var k in formDataHeaders)
|
|
57
|
+
{
|
|
58
|
+
var v = formDataHeaders[k];
|
|
59
|
+
requestConfig.headers[k] = v;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (config.qs) {
|
|
64
|
+
requestConfig.params = config.qs;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (config.json) {
|
|
68
|
+
requestConfig.data = config.json;
|
|
69
|
+
|
|
70
|
+
if (!requestConfig.headers["content-type"]) {
|
|
71
|
+
requestConfig.headers["content-type"] = "application/json";
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (config.data)
|
|
76
|
+
{
|
|
77
|
+
requestConfig.data = config.data;
|
|
78
|
+
|
|
79
|
+
if (!requestConfig.headers["content-type"])
|
|
80
|
+
{
|
|
81
|
+
if (!requestConfig.data)
|
|
82
|
+
{
|
|
83
|
+
if (requestConfig.data.getHeaders)
|
|
84
|
+
{
|
|
85
|
+
// assume this is a FormData and skip
|
|
86
|
+
}
|
|
87
|
+
else if (typeof(requestConfig.data) === "object")
|
|
88
|
+
{
|
|
89
|
+
// send as json
|
|
90
|
+
requestConfig.headers["content-type"] = "application/json";
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (config.responseType) {
|
|
97
|
+
requestConfig.responseType = config.responseType;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
/*
|
|
102
|
+
if (requestConfig.url.toLowerCase().indexOf("https:") > -1)
|
|
103
|
+
{
|
|
104
|
+
requestConfig.httpsAgent = https.globalAgent;
|
|
105
|
+
}
|
|
106
|
+
else
|
|
107
|
+
{
|
|
108
|
+
requestConfig.httpAgent = http.globalAgent;
|
|
109
|
+
}
|
|
110
|
+
*/
|
|
111
|
+
|
|
112
|
+
axios.request(requestConfig).then(function(response) {
|
|
113
|
+
callback(null, response, response.data);
|
|
114
|
+
}, function(error) {
|
|
115
|
+
callback(error);
|
|
116
|
+
});
|
|
117
|
+
};
|
package/util/util.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
var fs = require("fs");
|
|
2
2
|
var path = require("path");
|
|
3
|
-
var request = require("request");
|
|
4
3
|
var mime = require("mime");
|
|
5
4
|
var os = require("os");
|
|
6
5
|
var async = require("async");
|
|
@@ -22,6 +21,8 @@ var JSON5 = require("json5");
|
|
|
22
21
|
|
|
23
22
|
var uuidv4 = require("uuid").v4;
|
|
24
23
|
|
|
24
|
+
var request = require("./request");
|
|
25
|
+
|
|
25
26
|
var VALID_IP_ADDRESS_REGEX_STRING = "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$";
|
|
26
27
|
|
|
27
28
|
exports = module.exports;
|
|
@@ -684,16 +685,6 @@ var retryGitanaRequest = exports.retryGitanaRequest = function(logMethod, gitana
|
|
|
684
685
|
});
|
|
685
686
|
}
|
|
686
687
|
|
|
687
|
-
// make sure agent is applied
|
|
688
|
-
if (!config.agent && config.url)
|
|
689
|
-
{
|
|
690
|
-
var agent = getAgent(config.url);
|
|
691
|
-
if (agent)
|
|
692
|
-
{
|
|
693
|
-
config.agent = agent;
|
|
694
|
-
}
|
|
695
|
-
}
|
|
696
|
-
|
|
697
688
|
// make sure we have a headers object
|
|
698
689
|
if (!config.headers)
|
|
699
690
|
{
|
|
@@ -716,11 +707,11 @@ var retryGitanaRequest = exports.retryGitanaRequest = function(logMethod, gitana
|
|
|
716
707
|
if (response)
|
|
717
708
|
{
|
|
718
709
|
// ok case (just callback)
|
|
719
|
-
if (response.
|
|
710
|
+
if (response.status === 200)
|
|
720
711
|
{
|
|
721
712
|
return cb(err, response, body);
|
|
722
713
|
}
|
|
723
|
-
else if (response.
|
|
714
|
+
else if (response.status === 429)
|
|
724
715
|
{
|
|
725
716
|
// we heard "too many requests", so we wait a bit and then retry
|
|
726
717
|
// TODO: look at HTTP headers to determine how long to wait?
|
|
@@ -728,7 +719,7 @@ var retryGitanaRequest = exports.retryGitanaRequest = function(logMethod, gitana
|
|
|
728
719
|
logMethod("Too Many Requests heard, attempting retry (" + (currentAttempts + 1) + " / " + maxAttempts + ")");
|
|
729
720
|
_retryHandler(gitana, config, currentAttempts, maxAttempts, {
|
|
730
721
|
"message": "Heard 429 Too Many Requests",
|
|
731
|
-
"code": response.
|
|
722
|
+
"code": response.status,
|
|
732
723
|
"body": body,
|
|
733
724
|
"err": err
|
|
734
725
|
}, cb);
|
|
@@ -764,7 +755,7 @@ var retryGitanaRequest = exports.retryGitanaRequest = function(logMethod, gitana
|
|
|
764
755
|
// refresh the access token and then retry
|
|
765
756
|
return _invalidTokenRetryHandler(gitana, config, currentAttempts, maxAttempts, {
|
|
766
757
|
"message": "Unable to refresh access token and retry",
|
|
767
|
-
"code": response.
|
|
758
|
+
"code": response.status,
|
|
768
759
|
"body": body,
|
|
769
760
|
"err": err
|
|
770
761
|
}, cb);
|
|
@@ -1083,7 +1074,6 @@ var applyResponseContentType = exports.applyResponseContentType = function(respo
|
|
|
1083
1074
|
{
|
|
1084
1075
|
var ext = path.extname(filename);
|
|
1085
1076
|
if (ext) {
|
|
1086
|
-
//contentType = mime.lookup(ext);
|
|
1087
1077
|
contentType = lookupMimeType(ext);
|
|
1088
1078
|
}
|
|
1089
1079
|
}
|
|
@@ -1094,7 +1084,6 @@ var applyResponseContentType = exports.applyResponseContentType = function(respo
|
|
|
1094
1084
|
var ext = path.extname(filename);
|
|
1095
1085
|
if (ext)
|
|
1096
1086
|
{
|
|
1097
|
-
//contentType = mime.lookup(ext);
|
|
1098
1087
|
contentType = lookupMimeType(ext);
|
|
1099
1088
|
}
|
|
1100
1089
|
}
|
|
@@ -1383,7 +1372,7 @@ var isUndefined = exports.isUndefined = function(obj) {
|
|
|
1383
1372
|
var lookupMimeType = exports.lookupMimeType = function(ext) {
|
|
1384
1373
|
|
|
1385
1374
|
// rely on the mimetype library for base handling
|
|
1386
|
-
var mimetype = mime.
|
|
1375
|
+
var mimetype = mime.getType(ext);
|
|
1387
1376
|
|
|
1388
1377
|
var extension = ext;
|
|
1389
1378
|
if (extension && extension.indexOf(".") === 0)
|
|
@@ -1788,10 +1777,11 @@ var zip = exports.zip = function(directoryPath, writableStream)
|
|
|
1788
1777
|
* @param {string} protocol
|
|
1789
1778
|
* @param {string} host
|
|
1790
1779
|
* @param [number|string] port
|
|
1780
|
+
* @param {string} path
|
|
1791
1781
|
*
|
|
1792
1782
|
* @type {Function}
|
|
1793
1783
|
*/
|
|
1794
|
-
var asURL = exports.asURL = function(protocol, host, port)
|
|
1784
|
+
var asURL = exports.asURL = function(protocol, host, port, path)
|
|
1795
1785
|
{
|
|
1796
1786
|
// protocol lower case
|
|
1797
1787
|
protocol = protocol.toLowerCase();
|
|
@@ -1816,7 +1806,20 @@ var asURL = exports.asURL = function(protocol, host, port)
|
|
|
1816
1806
|
url += ":" + port;
|
|
1817
1807
|
}
|
|
1818
1808
|
}
|
|
1819
|
-
|
|
1809
|
+
|
|
1810
|
+
// include url "path" if defined
|
|
1811
|
+
if (path) {
|
|
1812
|
+
path = '/' + path;
|
|
1813
|
+
path = path.replace(/\/+/g, '/'); // ensure no extra '/' characters
|
|
1814
|
+
if (path.endsWith('/')) {
|
|
1815
|
+
// remove trailing '/' character
|
|
1816
|
+
path = path.substring(0, path.length - 1);
|
|
1817
|
+
}
|
|
1818
|
+
if (path) {
|
|
1819
|
+
url += path;
|
|
1820
|
+
}
|
|
1821
|
+
}
|
|
1822
|
+
|
|
1820
1823
|
return url;
|
|
1821
1824
|
};
|
|
1822
1825
|
|
|
@@ -1867,22 +1870,6 @@ var isHttp = exports.isHttp = function(url)
|
|
|
1867
1870
|
return url.toLowerCase().startsWith("http://");
|
|
1868
1871
|
};
|
|
1869
1872
|
|
|
1870
|
-
var getAgent = exports.getAgent = function(url)
|
|
1871
|
-
{
|
|
1872
|
-
var agent = http.globalAgent;
|
|
1873
|
-
|
|
1874
|
-
if (url.indexOf("https://") === 0)
|
|
1875
|
-
{
|
|
1876
|
-
agent = https.globalAgent;
|
|
1877
|
-
}
|
|
1878
|
-
else if (url.indexOf("http://") === 0)
|
|
1879
|
-
{
|
|
1880
|
-
agent = http.globalAgent;
|
|
1881
|
-
}
|
|
1882
|
-
|
|
1883
|
-
return agent;
|
|
1884
|
-
};
|
|
1885
|
-
|
|
1886
1873
|
/*
|
|
1887
1874
|
var selectLeastPrivilegedGitana = exports.selectLeastPrivilegedGitana = function(req)
|
|
1888
1875
|
{
|