cloudcms-server 3.2.296 → 3.2.298
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/duster/helpers/sample/nyt.js +6 -7
- package/framework/controllers.js +0 -1
- package/index.js +8 -0
- package/insight/insight.js +1 -4
- package/middleware/admin/admin.js +1 -1
- package/middleware/awareness/plugins/editorial.js +5 -15
- package/middleware/driver-config/driver-config.js +0 -6
- package/middleware/form/form.js +15 -30
- package/middleware/stores/store.js +0 -3
- package/middleware/virtual-config/virtual-config.js +8 -8
- package/middleware/virtual-files/virtual-files.js +0 -3
- package/middleware/welcome/welcome.js +0 -3
- package/package.json +5 -6
- package/util/auth.js +7 -18
- package/util/cloudcms.js +54 -60
- package/util/proxy-factory.js +1 -4
- package/util/renditions.js +10 -10
- package/util/request.js +135 -0
- package/util/util.js +12 -18
- package/d1/index.js +0 -629
- package/d1/index.js.works +0 -203
- package/d1/package.json +0 -86
- package/d1/package.json.works +0 -14
- package/util/proxy-factory.http2-proxy.js +0 -281
package/d1/index.js.works
DELETED
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
var createProxyHandler = function(protocol, hostname, port, pathPrefix)
|
|
2
|
-
{
|
|
3
|
-
const proxy = require("http2-proxy");
|
|
4
|
-
const finalhandler = require('finalhandler')
|
|
5
|
-
|
|
6
|
-
const defaultWebHandler = function(err, req, res) {
|
|
7
|
-
if (err)
|
|
8
|
-
{
|
|
9
|
-
console.log("A web proxy error was caught, path: " + req.path + ", err: ", err);
|
|
10
|
-
try { res.status(500); } catch (e) { }
|
|
11
|
-
try { res.end('Something went wrong while proxying the request.'); } catch (e) { }
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
finalhandler(req, res)(err);
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
// web
|
|
18
|
-
var webConfig = {};
|
|
19
|
-
webConfig.hostname = hostname;
|
|
20
|
-
webConfig.port = port;
|
|
21
|
-
webConfig.protocol = protocol;
|
|
22
|
-
//webConfig.path = null;
|
|
23
|
-
webConfig.timeout = 120000;
|
|
24
|
-
webConfig.proxyTimeout = 120000;
|
|
25
|
-
webConfig.proxyName = "Cloud CMS UI Proxy";
|
|
26
|
-
webConfig.onReq = function(req, options) {
|
|
27
|
-
|
|
28
|
-
if (!options.headers) {
|
|
29
|
-
options.headers = {};
|
|
30
|
-
}
|
|
31
|
-
var headers = options.headers;
|
|
32
|
-
|
|
33
|
-
if (options.path && options.path.startsWith("/proxy")) {
|
|
34
|
-
options.path = options.path.substring(6);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (pathPrefix) {
|
|
38
|
-
options.path = path.join(pathPrefix, options.path);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// used to auto-assign the client header for /oauth/token requests
|
|
42
|
-
//oauth2.autoProxy(req);
|
|
43
|
-
|
|
44
|
-
// copy domain host into "x-cloudcms-domainhost"
|
|
45
|
-
if (req.domainHost) {
|
|
46
|
-
headers["x-cloudcms-domainhost"] = req.domainHost; // this could be "localhost"
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// copy virtual host into "x-cloudcms-virtualhost"
|
|
50
|
-
if (req.virtualHost) {
|
|
51
|
-
headers["x-cloudcms-virtualhost"] = req.virtualHost; // this could be "root.cloudcms.net" or "abc.cloudcms.net"
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// copy deployment descriptor info
|
|
55
|
-
if (req.descriptor)
|
|
56
|
-
{
|
|
57
|
-
if (req.descriptor.tenant)
|
|
58
|
-
{
|
|
59
|
-
if (req.descriptor.tenant.id)
|
|
60
|
-
{
|
|
61
|
-
headers["x-cloudcms-tenant-id"] = req.descriptor.tenant.id;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (req.descriptor.tenant.title)
|
|
65
|
-
{
|
|
66
|
-
headers["x-cloudcms-tenant-title"] = req.descriptor.tenant.title;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (req.descriptor.application)
|
|
71
|
-
{
|
|
72
|
-
if (req.descriptor.application.id)
|
|
73
|
-
{
|
|
74
|
-
headers["x-cloudcms-application-id"] = req.descriptor.application.id;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if (req.descriptor.application.title)
|
|
78
|
-
{
|
|
79
|
-
headers["x-cloudcms-application-title"] = req.descriptor.application.title;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// set optional "x-cloudcms-origin" header
|
|
85
|
-
var cloudcmsOrigin = null;
|
|
86
|
-
if (req.virtualHost)
|
|
87
|
-
{
|
|
88
|
-
cloudcmsOrigin = req.virtualHost;
|
|
89
|
-
}
|
|
90
|
-
if (cloudcmsOrigin)
|
|
91
|
-
{
|
|
92
|
-
headers["x-cloudcms-origin"] = cloudcmsOrigin;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// set x-cloudcms-server-version header
|
|
96
|
-
//headers["x-cloudcms-server-version"] = process.env.CLOUDCMS_APPSERVER_PACKAGE_VERSION;
|
|
97
|
-
|
|
98
|
-
// keep alive
|
|
99
|
-
//req.headers["connection"] = "keep-alive";
|
|
100
|
-
|
|
101
|
-
// if the incoming request didn't have an "Authorization" header
|
|
102
|
-
// and we have a logged in Gitana User via Auth, then set authorization header to Bearer Access Token
|
|
103
|
-
if (!req.headers["authorization"])
|
|
104
|
-
{
|
|
105
|
-
if (req.gitana_user)
|
|
106
|
-
{
|
|
107
|
-
headers["authorization"] = "Bearer " + req.gitana_user.getDriver().http.accessToken();
|
|
108
|
-
}
|
|
109
|
-
else if (req.gitana_proxy_access_token)
|
|
110
|
-
{
|
|
111
|
-
headers["authorization"] = "Bearer " + req.gitana_proxy_access_token;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
webConfig.onRes = function(req, res, proxyRes) {
|
|
116
|
-
|
|
117
|
-
// if (req.gitana_user)
|
|
118
|
-
// {
|
|
119
|
-
// var chunks = [];
|
|
120
|
-
//
|
|
121
|
-
// // triggers on data receive
|
|
122
|
-
// proxyRes.on('data', function(chunk) {
|
|
123
|
-
// // add received chunk to chunks array
|
|
124
|
-
// chunks.push(chunk);
|
|
125
|
-
// });
|
|
126
|
-
//
|
|
127
|
-
// proxyRes.on("end", function () {
|
|
128
|
-
//
|
|
129
|
-
// if (proxyRes.statusCode === 401)
|
|
130
|
-
// {
|
|
131
|
-
// var text = "" + Buffer.concat(chunks);
|
|
132
|
-
// if (text && (text.indexOf("invalid_token") > -1) || (text.indexOf("invalid_grant") > -1))
|
|
133
|
-
// {
|
|
134
|
-
// var identifier = req.identity_properties.provider_id + "/" + req.identity_properties.user_identifier;
|
|
135
|
-
//
|
|
136
|
-
// _LOCK([identifier], function(err, releaseLockFn) {
|
|
137
|
-
//
|
|
138
|
-
// if (err)
|
|
139
|
-
// {
|
|
140
|
-
// // failed to acquire lock
|
|
141
|
-
// console.log("FAILED TO ACQUIRE LOCK", err);
|
|
142
|
-
// req.log("FAILED TO ACQUIRE LOCK", err);
|
|
143
|
-
// try { releaseLockFn(); } catch (e) { }
|
|
144
|
-
// return;
|
|
145
|
-
// }
|
|
146
|
-
//
|
|
147
|
-
// var cleanup = function (full)
|
|
148
|
-
// {
|
|
149
|
-
// delete Gitana.APPS[req.identity_properties.token];
|
|
150
|
-
// delete Gitana.PLATFORM_CACHE[req.identity_properties.token];
|
|
151
|
-
//
|
|
152
|
-
// if (full) {
|
|
153
|
-
// auth.removeUserCacheEntry(identifier);
|
|
154
|
-
// }
|
|
155
|
-
// };
|
|
156
|
-
//
|
|
157
|
-
// // null out the access token
|
|
158
|
-
// // this will force the refresh token to be used to get a new one on the next request
|
|
159
|
-
// req.gitana_user.getDriver().http.refresh(function (err) {
|
|
160
|
-
//
|
|
161
|
-
// if (err) {
|
|
162
|
-
// cleanup(true);
|
|
163
|
-
// req.log("Invalidated auth state for gitana user: " + req.identity_properties.token);
|
|
164
|
-
// return releaseLockFn();
|
|
165
|
-
// }
|
|
166
|
-
//
|
|
167
|
-
// req.gitana_user.getDriver().reloadAuthInfo(function () {
|
|
168
|
-
// cleanup(true);
|
|
169
|
-
// req.log("Refreshed token for gitana user: " + req.identity_properties.token);
|
|
170
|
-
// releaseLockFn();
|
|
171
|
-
// });
|
|
172
|
-
// });
|
|
173
|
-
// });
|
|
174
|
-
// }
|
|
175
|
-
//
|
|
176
|
-
// }
|
|
177
|
-
// });
|
|
178
|
-
// }
|
|
179
|
-
|
|
180
|
-
//res.setHeader('x-powered-by', 'cloudcms');
|
|
181
|
-
res.writeHead(proxyRes.statusCode, proxyRes.headers)
|
|
182
|
-
proxyRes.pipe(res)
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
var proxyRequestHandler = function(req, res) {
|
|
186
|
-
proxy.web(req, res, webConfig, function(err, req, res) {
|
|
187
|
-
defaultWebHandler(err, req, res);
|
|
188
|
-
});
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
return proxyRequestHandler;
|
|
192
|
-
};
|
|
193
|
-
|
|
194
|
-
const http = require("http");
|
|
195
|
-
const server = http.createServer()
|
|
196
|
-
server.listen(3000);
|
|
197
|
-
|
|
198
|
-
var proxyRequestHandler = createProxyHandler("http", "api.default.svc.cluster.local", 80);
|
|
199
|
-
server.on('request', (req, res) => {
|
|
200
|
-
req.virtualHost = "mt85.us1.cloudcms.net";
|
|
201
|
-
|
|
202
|
-
proxyRequestHandler(req, res);
|
|
203
|
-
});
|
package/d1/package.json
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "d1",
|
|
3
|
-
"description": "D1",
|
|
4
|
-
"version": "0.0.1",
|
|
5
|
-
"dependencies": {
|
|
6
|
-
"@socket.io/cluster-adapter": "^0.2.0",
|
|
7
|
-
"@socket.io/redis-adapter": "^7.2.0",
|
|
8
|
-
"@socket.io/sticky": "^1.0.1",
|
|
9
|
-
"accepts": "^1.3.8",
|
|
10
|
-
"agentkeepalive": "^4.2.1",
|
|
11
|
-
"alpaca": "^1.5.27",
|
|
12
|
-
"archiver": "^1.3.0",
|
|
13
|
-
"async": "^3.2.3",
|
|
14
|
-
"async-lock": "^1.3.2",
|
|
15
|
-
"aws-sdk": "^2.1208.0",
|
|
16
|
-
"basic-auth": "^2.0.1",
|
|
17
|
-
"body-parser": "^1.20.0",
|
|
18
|
-
"bytes": "^2.5.0",
|
|
19
|
-
"canoe": "^0.3.3",
|
|
20
|
-
"clone": "^2.1.2",
|
|
21
|
-
"connect-flash": "^0.1.1",
|
|
22
|
-
"connect-multiparty": "^2.2.0",
|
|
23
|
-
"connect-redis": "^6.1.3",
|
|
24
|
-
"consolidate": "^0.14.5",
|
|
25
|
-
"cookie-parser": "^1.4.4",
|
|
26
|
-
"debug": "^2.6.9",
|
|
27
|
-
"dustjs-helpers": "1.7.4",
|
|
28
|
-
"dustjs-linkedin": "3.0.1",
|
|
29
|
-
"errorhandler": "^1.5.1",
|
|
30
|
-
"express": "^4.18.1",
|
|
31
|
-
"express-session": "^1.17.3",
|
|
32
|
-
"express-useragent": "^1.0.15",
|
|
33
|
-
"extend-with-super": "^2.0.0",
|
|
34
|
-
"finalhandler": "^1.2.0",
|
|
35
|
-
"gitana": "^1.0.322",
|
|
36
|
-
"handlebars": "^4.4.2",
|
|
37
|
-
"hbs": "^4.0.5",
|
|
38
|
-
"helmet": "^4.6.0",
|
|
39
|
-
"http2-proxy": "^5.0.53",
|
|
40
|
-
"ioredis": "4.28.5",
|
|
41
|
-
"json5": "^1.0.1",
|
|
42
|
-
"jsonwebtoken": "^8.5.1",
|
|
43
|
-
"klaw": "^1.3.1",
|
|
44
|
-
"lru-cache": "^4.1.5",
|
|
45
|
-
"marked": "^4.0.14",
|
|
46
|
-
"memorystore": "^1.6.1",
|
|
47
|
-
"mime": "^1.6.0",
|
|
48
|
-
"mkdirp": "^0.5.1",
|
|
49
|
-
"moment": "^2.24.0",
|
|
50
|
-
"morgan": "^1.9.1",
|
|
51
|
-
"object-hash": "^1.3.1",
|
|
52
|
-
"object-merge": "^2.5.1",
|
|
53
|
-
"on-headers": "^1.0.2",
|
|
54
|
-
"passport": "^0.4.0",
|
|
55
|
-
"passport-cas": "^0.0.3",
|
|
56
|
-
"passport-facebook": "^2.1.1",
|
|
57
|
-
"passport-github": "^1.1.0",
|
|
58
|
-
"passport-google-oauth": "^1.0.0",
|
|
59
|
-
"passport-linkedin": "^1.0.0",
|
|
60
|
-
"passport-local": "^1.0.0",
|
|
61
|
-
"passport-oauth": "^1.0.0",
|
|
62
|
-
"passport-saml": "^2.2.0",
|
|
63
|
-
"passport-twitter": "^0.1.5",
|
|
64
|
-
"pkginfo": "^0.4.1",
|
|
65
|
-
"random-js": "^1.0.8",
|
|
66
|
-
"recursive-readdir": "^2.2.2",
|
|
67
|
-
"redis": "^4.2.0",
|
|
68
|
-
"redlock": "4.2.0",
|
|
69
|
-
"request": "^2.88.0",
|
|
70
|
-
"request-param": "^1.0.1",
|
|
71
|
-
"response-time": "^2.3.2",
|
|
72
|
-
"semver": "^7.3.7",
|
|
73
|
-
"serve-favicon": "^2.5.0",
|
|
74
|
-
"session-file-store": "^0.2.2",
|
|
75
|
-
"sha1": "^1.1.1",
|
|
76
|
-
"socket.io": "^4.5.1",
|
|
77
|
-
"ssl-root-cas": "^1.3.1",
|
|
78
|
-
"stomp-client": "^0.9.0",
|
|
79
|
-
"targz": "^1.0.1",
|
|
80
|
-
"temp": "^0.8.3",
|
|
81
|
-
"uuid": "^3.3.2",
|
|
82
|
-
"vm2": "^3.8.4",
|
|
83
|
-
"watch": "^0.13.0",
|
|
84
|
-
"winston": "^3.3.3"
|
|
85
|
-
}
|
|
86
|
-
}
|
package/d1/package.json.works
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"author": {
|
|
3
|
-
"name": "Gitana Software, Inc.",
|
|
4
|
-
"email": "info@cloudcms.com",
|
|
5
|
-
"url": "https://www.cloudcms.com"
|
|
6
|
-
},
|
|
7
|
-
"name": "d1",
|
|
8
|
-
"description": "D1",
|
|
9
|
-
"version": "0.0.1",
|
|
10
|
-
"dependencies": {
|
|
11
|
-
"http2-proxy": "^5.0.53",
|
|
12
|
-
"finalhandler": "^1.2.0"
|
|
13
|
-
}
|
|
14
|
-
}
|
|
@@ -1,281 +0,0 @@
|
|
|
1
|
-
var http = require("http");
|
|
2
|
-
var https = require("https");
|
|
3
|
-
var path = require("path");
|
|
4
|
-
|
|
5
|
-
var auth = require("./auth");
|
|
6
|
-
var util = require("./util");
|
|
7
|
-
|
|
8
|
-
var oauth2 = require("./oauth2")();
|
|
9
|
-
|
|
10
|
-
var urlTool = require("url");
|
|
11
|
-
const finalhandler = require("finalhandler");
|
|
12
|
-
|
|
13
|
-
var LRU = require("lru-cache");
|
|
14
|
-
|
|
15
|
-
var exports = module.exports;
|
|
16
|
-
|
|
17
|
-
var _LOCK = function(lockIdentifiers, workFunction)
|
|
18
|
-
{
|
|
19
|
-
var name = lockIdentifiers.join("_");
|
|
20
|
-
process.locks.lock(name, workFunction);
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
var NAMED_PROXY_HANDLERS_CACHE = new LRU({
|
|
24
|
-
max: 200,
|
|
25
|
-
ttl: 1000 * 60 * 60 // 60 minutes
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
var acquireProxyHandler = exports.acquireProxyHandler = function(proxyTarget, pathPrefix, callback)
|
|
29
|
-
{
|
|
30
|
-
var name = path.join(proxyTarget, (pathPrefix || "/"));
|
|
31
|
-
|
|
32
|
-
// is it already in LRU cache?
|
|
33
|
-
// if so hand it back
|
|
34
|
-
var _cachedHandler = NAMED_PROXY_HANDLERS_CACHE[name];
|
|
35
|
-
if (_cachedHandler)
|
|
36
|
-
{
|
|
37
|
-
return callback(null, _cachedHandler);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// take out a thread lock
|
|
41
|
-
_LOCK(["acquireProxyHandler", name], function(err, releaseLockFn) {
|
|
42
|
-
|
|
43
|
-
if (err)
|
|
44
|
-
{
|
|
45
|
-
console.log("Failed to acquire proxy handler: " + name + ", err: ", err);
|
|
46
|
-
|
|
47
|
-
// failed to acquire lock
|
|
48
|
-
return callback(err);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// second check to make sure another thread didn't create the handler in the meantime
|
|
52
|
-
_cachedHandler = NAMED_PROXY_HANDLERS_CACHE[name];
|
|
53
|
-
if (_cachedHandler)
|
|
54
|
-
{
|
|
55
|
-
releaseLockFn();
|
|
56
|
-
return callback(null, _cachedHandler);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// create the proxy handler and cache it into LRU cache
|
|
60
|
-
//console.log("Acquiring proxy handler: " + name + ", for target: " + proxyTarget + " and prefix: " + pathPrefix);
|
|
61
|
-
_cachedHandler = createProxyHandler(proxyTarget, pathPrefix);
|
|
62
|
-
|
|
63
|
-
// store back into LRU cache
|
|
64
|
-
NAMED_PROXY_HANDLERS_CACHE[name] = _cachedHandler;
|
|
65
|
-
|
|
66
|
-
releaseLockFn();
|
|
67
|
-
callback(null, _cachedHandler);
|
|
68
|
-
});
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
var createProxyHandler = function(proxyTarget, pathPrefix)
|
|
75
|
-
{
|
|
76
|
-
const proxy = require("http2-proxy");
|
|
77
|
-
const finalhandler = require('finalhandler')
|
|
78
|
-
|
|
79
|
-
const defaultWebHandler = function(err, req, res) {
|
|
80
|
-
if (err)
|
|
81
|
-
{
|
|
82
|
-
console.log("A web proxy error was caught, path: " + req.path + ", err: ", err);
|
|
83
|
-
try { res.status(500); } catch (e) { }
|
|
84
|
-
try { res.end('Something went wrong while proxying the request.'); } catch (e) { }
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
finalhandler(req, res)(err);
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
// const defaultWsHandler = function(err, req, socket, head) {
|
|
91
|
-
// if (err) {
|
|
92
|
-
// console.error('proxy error (ws)', err);
|
|
93
|
-
// socket.destroy();
|
|
94
|
-
// }
|
|
95
|
-
// };
|
|
96
|
-
|
|
97
|
-
//console.log("Proxy Target: " + proxyTarget);
|
|
98
|
-
|
|
99
|
-
var hostname = urlTool.parse(proxyTarget).hostname;
|
|
100
|
-
var port = urlTool.parse(proxyTarget).port;
|
|
101
|
-
var protocol = urlTool.parse(proxyTarget).protocol;
|
|
102
|
-
|
|
103
|
-
// web
|
|
104
|
-
var webConfig = {};
|
|
105
|
-
webConfig.hostname = hostname;
|
|
106
|
-
webConfig.port = port;
|
|
107
|
-
webConfig.protocol = protocol;
|
|
108
|
-
//webConfig.path = null;
|
|
109
|
-
webConfig.timeout = 120000;
|
|
110
|
-
webConfig.proxyTimeout = 120000;
|
|
111
|
-
webConfig.proxyName = "Cloud CMS UI Proxy";
|
|
112
|
-
webConfig.onReq = function(req, options) {
|
|
113
|
-
|
|
114
|
-
if (!options.headers) {
|
|
115
|
-
options.headers = {};
|
|
116
|
-
}
|
|
117
|
-
var headers = options.headers;
|
|
118
|
-
|
|
119
|
-
if (options.path && options.path.startsWith("/proxy")) {
|
|
120
|
-
options.path = options.path.substring(6);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
if (pathPrefix) {
|
|
124
|
-
options.path = path.join(pathPrefix, options.path);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// used to auto-assign the client header for /oauth/token requests
|
|
128
|
-
oauth2.autoProxy(req);
|
|
129
|
-
|
|
130
|
-
// copy domain host into "x-cloudcms-domainhost"
|
|
131
|
-
if (req.domainHost) {
|
|
132
|
-
headers["x-cloudcms-domainhost"] = req.domainHost; // this could be "localhost"
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// copy virtual host into "x-cloudcms-virtualhost"
|
|
136
|
-
if (req.virtualHost) {
|
|
137
|
-
headers["x-cloudcms-virtualhost"] = req.virtualHost; // this could be "root.cloudcms.net" or "abc.cloudcms.net"
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
// copy deployment descriptor info
|
|
141
|
-
if (req.descriptor)
|
|
142
|
-
{
|
|
143
|
-
if (req.descriptor.tenant)
|
|
144
|
-
{
|
|
145
|
-
if (req.descriptor.tenant.id)
|
|
146
|
-
{
|
|
147
|
-
headers["x-cloudcms-tenant-id"] = req.descriptor.tenant.id;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
if (req.descriptor.tenant.title)
|
|
151
|
-
{
|
|
152
|
-
headers["x-cloudcms-tenant-title"] = req.descriptor.tenant.title;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
if (req.descriptor.application)
|
|
157
|
-
{
|
|
158
|
-
if (req.descriptor.application.id)
|
|
159
|
-
{
|
|
160
|
-
headers["x-cloudcms-application-id"] = req.descriptor.application.id;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
if (req.descriptor.application.title)
|
|
164
|
-
{
|
|
165
|
-
headers["x-cloudcms-application-title"] = req.descriptor.application.title;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// set optional "x-cloudcms-origin" header
|
|
171
|
-
var cloudcmsOrigin = null;
|
|
172
|
-
if (req.virtualHost)
|
|
173
|
-
{
|
|
174
|
-
cloudcmsOrigin = req.virtualHost;
|
|
175
|
-
}
|
|
176
|
-
if (cloudcmsOrigin)
|
|
177
|
-
{
|
|
178
|
-
headers["x-cloudcms-origin"] = cloudcmsOrigin;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
// set x-cloudcms-server-version header
|
|
182
|
-
headers["x-cloudcms-server-version"] = process.env.CLOUDCMS_APPSERVER_PACKAGE_VERSION;
|
|
183
|
-
|
|
184
|
-
// keep alive
|
|
185
|
-
//req.headers["connection"] = "keep-alive";
|
|
186
|
-
|
|
187
|
-
// if the incoming request didn't have an "Authorization" header
|
|
188
|
-
// and we have a logged in Gitana User via Auth, then set authorization header to Bearer Access Token
|
|
189
|
-
if (!req.headers["authorization"])
|
|
190
|
-
{
|
|
191
|
-
if (req.gitana_user)
|
|
192
|
-
{
|
|
193
|
-
headers["authorization"] = "Bearer " + req.gitana_user.getDriver().http.accessToken();
|
|
194
|
-
}
|
|
195
|
-
else if (req.gitana_proxy_access_token)
|
|
196
|
-
{
|
|
197
|
-
headers["authorization"] = "Bearer " + req.gitana_proxy_access_token;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
};
|
|
201
|
-
webConfig.onRes = function(req, res, proxyRes) {
|
|
202
|
-
|
|
203
|
-
if (req.gitana_user)
|
|
204
|
-
{
|
|
205
|
-
var chunks = [];
|
|
206
|
-
|
|
207
|
-
// triggers on data receive
|
|
208
|
-
proxyRes.on('data', function(chunk) {
|
|
209
|
-
// add received chunk to chunks array
|
|
210
|
-
chunks.push(chunk);
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
proxyRes.on("end", function () {
|
|
214
|
-
|
|
215
|
-
if (proxyRes.statusCode === 401)
|
|
216
|
-
{
|
|
217
|
-
var text = "" + Buffer.concat(chunks);
|
|
218
|
-
if (text && (text.indexOf("invalid_token") > -1) || (text.indexOf("invalid_grant") > -1))
|
|
219
|
-
{
|
|
220
|
-
var identifier = req.identity_properties.provider_id + "/" + req.identity_properties.user_identifier;
|
|
221
|
-
|
|
222
|
-
_LOCK([identifier], function(err, releaseLockFn) {
|
|
223
|
-
|
|
224
|
-
if (err)
|
|
225
|
-
{
|
|
226
|
-
// failed to acquire lock
|
|
227
|
-
console.log("FAILED TO ACQUIRE LOCK", err);
|
|
228
|
-
req.log("FAILED TO ACQUIRE LOCK", err);
|
|
229
|
-
try { releaseLockFn(); } catch (e) { }
|
|
230
|
-
return;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
var cleanup = function (full)
|
|
234
|
-
{
|
|
235
|
-
delete Gitana.APPS[req.identity_properties.token];
|
|
236
|
-
delete Gitana.PLATFORM_CACHE[req.identity_properties.token];
|
|
237
|
-
|
|
238
|
-
if (full) {
|
|
239
|
-
auth.removeUserCacheEntry(identifier);
|
|
240
|
-
}
|
|
241
|
-
};
|
|
242
|
-
|
|
243
|
-
// null out the access token
|
|
244
|
-
// this will force the refresh token to be used to get a new one on the next request
|
|
245
|
-
req.gitana_user.getDriver().http.refresh(function (err) {
|
|
246
|
-
|
|
247
|
-
if (err) {
|
|
248
|
-
cleanup(true);
|
|
249
|
-
req.log("Invalidated auth state for gitana user: " + req.identity_properties.token);
|
|
250
|
-
return releaseLockFn();
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
req.gitana_user.getDriver().reloadAuthInfo(function () {
|
|
254
|
-
cleanup(true);
|
|
255
|
-
req.log("Refreshed token for gitana user: " + req.identity_properties.token);
|
|
256
|
-
releaseLockFn();
|
|
257
|
-
});
|
|
258
|
-
});
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
}
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
//res.setHeader('x-powered-by', 'cloudcms');
|
|
267
|
-
res.writeHead(proxyRes.statusCode, proxyRes.headers)
|
|
268
|
-
proxyRes.pipe(res)
|
|
269
|
-
};
|
|
270
|
-
|
|
271
|
-
var proxyRequestHandler = function(req, res) {
|
|
272
|
-
proxy.web(req, res, webConfig, function(err, req, res) {
|
|
273
|
-
defaultWebHandler(err, req, res);
|
|
274
|
-
});
|
|
275
|
-
};
|
|
276
|
-
|
|
277
|
-
// cookie domain rewrite?
|
|
278
|
-
// not needed - this is handled intrinsically by http2-proxy
|
|
279
|
-
|
|
280
|
-
return proxyRequestHandler;
|
|
281
|
-
};
|