cloudcms-server 0.9.275 → 3.2.278
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/LICENSE +1 -1
- package/middleware/proxy/proxy.js +1 -11
- package/package.json +8 -11
- package/util/proxy-factory.js +212 -178
- package/temp/http-proxy/.auto-changelog +0 -6
- package/temp/http-proxy/.gitattributes +0 -1
- package/temp/http-proxy/CHANGELOG.md +0 -1872
- package/temp/http-proxy/CODE_OF_CONDUCT.md +0 -74
- package/temp/http-proxy/LICENSE +0 -23
- package/temp/http-proxy/README.md +0 -568
- package/temp/http-proxy/codecov.yml +0 -10
- package/temp/http-proxy/index.js +0 -13
- package/temp/http-proxy/lib/http-proxy/common.js +0 -220
- package/temp/http-proxy/lib/http-proxy/index.js +0 -174
- package/temp/http-proxy/lib/http-proxy/passes/web-incoming.js +0 -174
- package/temp/http-proxy/lib/http-proxy/passes/web-outgoing.js +0 -135
- package/temp/http-proxy/lib/http-proxy/passes/ws-incoming.js +0 -141
- package/temp/http-proxy/lib/index.js +0 -13
- package/temp/http-proxy/package.json +0 -46
- package/temp/http-proxy/renovate.json +0 -19
- package/temp/node-http-proxy/.eslintignore +0 -3
- package/temp/node-http-proxy/.eslintrc.js +0 -21
- package/temp/node-http-proxy/.github/workflows/ci.yml +0 -30
- package/temp/node-http-proxy/.prettierrc +0 -7
- package/temp/node-http-proxy/CODE_OF_CONDUCT.md +0 -74
- package/temp/node-http-proxy/LICENSE +0 -23
- package/temp/node-http-proxy/README.md +0 -568
- package/temp/node-http-proxy/codecov.yml +0 -10
- package/temp/node-http-proxy/dist/http-proxy/common.js +0 -220
- package/temp/node-http-proxy/dist/http-proxy/index.js +0 -174
- package/temp/node-http-proxy/dist/http-proxy/passes/web-incoming.js +0 -174
- package/temp/node-http-proxy/dist/http-proxy/passes/web-outgoing.js +0 -135
- package/temp/node-http-proxy/dist/http-proxy/passes/ws-incoming.js +0 -141
- package/temp/node-http-proxy/dist/index.js +0 -13
- package/temp/node-http-proxy/lib/http-proxy/common.js +0 -265
- package/temp/node-http-proxy/lib/http-proxy/index.ts +0 -242
- package/temp/node-http-proxy/lib/http-proxy/passes/web-incoming.js +0 -208
- package/temp/node-http-proxy/lib/http-proxy/passes/web-outgoing.js +0 -163
- package/temp/node-http-proxy/lib/http-proxy/passes/ws-incoming.js +0 -179
- package/temp/node-http-proxy/lib/index.ts +0 -13
- package/temp/node-http-proxy/lib/types.d.ts +0 -277
- package/temp/node-http-proxy/package-lock.json +0 -5028
- package/temp/node-http-proxy/package.json +0 -47
- package/temp/node-http-proxy/tsconfig.build.json +0 -4
- package/temp/node-http-proxy/tsconfig.json +0 -115
- package/temp/node-http-proxy/vitest.config.ts +0 -9
package/LICENSE
CHANGED
|
@@ -1,16 +1,6 @@
|
|
|
1
1
|
var path = require('path');
|
|
2
|
-
// var fs = require('fs');
|
|
3
|
-
// var http = require('http');
|
|
4
|
-
// var https = require('https');
|
|
5
|
-
|
|
6
|
-
// var httpProxy = require('http-proxy');
|
|
7
|
-
|
|
8
|
-
// var oauth2 = require("../../util/oauth2")();
|
|
9
|
-
|
|
10
|
-
// var async = require("async");
|
|
11
2
|
|
|
12
3
|
var util = require("../../util/util");
|
|
13
|
-
// var auth = require("../../util/auth");
|
|
14
4
|
|
|
15
5
|
var proxyFactory = require("../../util/proxy-factory");
|
|
16
6
|
|
|
@@ -211,7 +201,7 @@ exports = module.exports = function()
|
|
|
211
201
|
contentStore.writeFile(filePath + ".cache", JSON.stringify(cacheInfo), function() {
|
|
212
202
|
_end.call(res, data, encoding);
|
|
213
203
|
});
|
|
214
|
-
|
|
204
|
+
};
|
|
215
205
|
|
|
216
206
|
callback();
|
|
217
207
|
});
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
},
|
|
7
7
|
"name": "cloudcms-server",
|
|
8
8
|
"description": "Cloud CMS Application Server Module",
|
|
9
|
-
"version": "
|
|
9
|
+
"version": "3.2.278",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
12
|
"url": "git://github.com/gitana/cloudcms-server.git"
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"@socket.io/redis-adapter": "^7.2.0",
|
|
17
17
|
"@socket.io/sticky": "^1.0.1",
|
|
18
18
|
"accepts": "^1.3.7",
|
|
19
|
-
"agentkeepalive": "^4.1
|
|
19
|
+
"agentkeepalive": "^4.2.1",
|
|
20
20
|
"alpaca": "^1.5.27",
|
|
21
21
|
"archiver": "^1.3.0",
|
|
22
22
|
"async": "^3.2.3",
|
|
@@ -40,13 +40,14 @@
|
|
|
40
40
|
"express-session": "^1.17.3",
|
|
41
41
|
"express-useragent": "^1.0.13",
|
|
42
42
|
"extend-with-super": "^2.0.0",
|
|
43
|
+
"finalhandler": "^1.2.0",
|
|
43
44
|
"gitana": "^1.0.322",
|
|
44
45
|
"handlebars": "^4.4.2",
|
|
45
46
|
"hbs": "^4.0.5",
|
|
46
47
|
"helmet": "^4.6.0",
|
|
47
|
-
"
|
|
48
|
+
"http2-proxy": "^5.0.53",
|
|
48
49
|
"ioredis": "4.28.5",
|
|
49
|
-
"json5": "^
|
|
50
|
+
"json5": "^2.2.1",
|
|
50
51
|
"jsonwebtoken": "^8.5.1",
|
|
51
52
|
"klaw": "^1.3.1",
|
|
52
53
|
"lru-cache": "^4.1.5",
|
|
@@ -56,7 +57,6 @@
|
|
|
56
57
|
"mkdirp": "^0.5.1",
|
|
57
58
|
"moment": "^2.24.0",
|
|
58
59
|
"morgan": "^1.9.1",
|
|
59
|
-
"npm": "^8.15.0",
|
|
60
60
|
"object-hash": "^1.3.1",
|
|
61
61
|
"object-merge": "^2.5.1",
|
|
62
62
|
"on-headers": "^1.0.2",
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
"recursive-readdir": "^2.2.2",
|
|
77
77
|
"redis": "^4.2.0",
|
|
78
78
|
"redlock": "4.2.0",
|
|
79
|
-
"request": "^2.88.
|
|
79
|
+
"request": "^2.88.2",
|
|
80
80
|
"request-param": "^1.0.1",
|
|
81
81
|
"response-time": "^2.3.2",
|
|
82
82
|
"semver": "^7.3.7",
|
|
@@ -89,13 +89,10 @@
|
|
|
89
89
|
"targz": "^1.0.1",
|
|
90
90
|
"temp": "^0.8.3",
|
|
91
91
|
"toobusy-js": "^0.5.1",
|
|
92
|
-
"uuid": "^
|
|
92
|
+
"uuid": "^8.3.2",
|
|
93
93
|
"vm2": "^3.8.4",
|
|
94
94
|
"watch": "^0.13.0",
|
|
95
|
-
"winston": "^3.3.3"
|
|
96
|
-
"eventemitter3": "^4.0.7",
|
|
97
|
-
"requires-port": "^1.0.0",
|
|
98
|
-
"follow-redirects": "^1.15.1"
|
|
95
|
+
"winston": "^3.3.3"
|
|
99
96
|
},
|
|
100
97
|
"contributors": [
|
|
101
98
|
{
|
package/util/proxy-factory.js
CHANGED
|
@@ -2,14 +2,13 @@ var http = require("http");
|
|
|
2
2
|
var https = require("https");
|
|
3
3
|
var path = require("path");
|
|
4
4
|
|
|
5
|
-
var httpProxy = require("../temp/http-proxy");
|
|
6
|
-
|
|
7
5
|
var auth = require("./auth");
|
|
8
6
|
var util = require("./util");
|
|
9
7
|
|
|
10
8
|
var oauth2 = require("./oauth2")();
|
|
11
9
|
|
|
12
10
|
var urlTool = require("url");
|
|
11
|
+
const finalhandler = require("finalhandler");
|
|
13
12
|
|
|
14
13
|
var exports = module.exports;
|
|
15
14
|
|
|
@@ -64,84 +63,141 @@ var acquireProxyHandler = exports.acquireProxyHandler = function(proxyTarget, pa
|
|
|
64
63
|
});
|
|
65
64
|
};
|
|
66
65
|
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
67
69
|
var createProxyHandler = function(proxyTarget, pathPrefix)
|
|
68
70
|
{
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
// HTTP/HTTPS Proxy Server to Cloud CMS
|
|
72
|
-
// Facilitates Cross-Domain communication between Browser and Cloud Server
|
|
73
|
-
// This must appear at the top of the app.js file (ahead of config) for things to work
|
|
74
|
-
//
|
|
75
|
-
////////////////////////////////////////////////////////////////////////////
|
|
71
|
+
const proxy = require("http2-proxy");
|
|
72
|
+
const finalhandler = require('finalhandler')
|
|
76
73
|
|
|
77
|
-
|
|
78
|
-
|
|
74
|
+
const defaultWebHandler = function(err, req, res) {
|
|
75
|
+
if (err)
|
|
76
|
+
{
|
|
77
|
+
console.log("A web proxy error was caught, path: " + req.path + ", err: ", err);
|
|
78
|
+
try { res.status(500); } catch (e) { }
|
|
79
|
+
try { res.end('Something went wrong while proxying the request.'); } catch (e) { }
|
|
80
|
+
}
|
|
79
81
|
|
|
80
|
-
|
|
81
|
-
// in http-proxy's common.js line 102, the host is only properly set up if changeOrigin is set to true
|
|
82
|
-
// this sets the "host" header and it has to match what is set at the network/transport level in a way
|
|
83
|
-
// (inner workings of Node http request)
|
|
84
|
-
//
|
|
85
|
-
var proxyConfig = {
|
|
86
|
-
"target": proxyTarget,
|
|
87
|
-
"agent": http.globalAgent,
|
|
88
|
-
"xfwd": false,
|
|
89
|
-
"proxyTimeout": process.defaultHttpTimeoutMs,
|
|
90
|
-
//"changeOrigin": true
|
|
91
|
-
"headers": {
|
|
92
|
-
"host": proxyHost
|
|
93
|
-
},
|
|
94
|
-
"cookieDomainRewrite": true
|
|
82
|
+
finalhandler(req, res)(err);
|
|
95
83
|
};
|
|
96
|
-
|
|
97
|
-
//
|
|
98
|
-
if (
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
//
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
res.writeHead(500, {
|
|
123
|
-
'Content-Type': 'text/plain'
|
|
124
|
-
});
|
|
84
|
+
|
|
85
|
+
// const defaultWsHandler = function(err, req, socket, head) {
|
|
86
|
+
// if (err) {
|
|
87
|
+
// console.error('proxy error (ws)', err);
|
|
88
|
+
// socket.destroy();
|
|
89
|
+
// }
|
|
90
|
+
// };
|
|
91
|
+
|
|
92
|
+
//console.log("Proxy Target: " + proxyTarget);
|
|
93
|
+
|
|
94
|
+
var hostname = urlTool.parse(proxyTarget).hostname;
|
|
95
|
+
var port = urlTool.parse(proxyTarget).port;
|
|
96
|
+
var protocol = urlTool.parse(proxyTarget).protocol;
|
|
97
|
+
|
|
98
|
+
// web
|
|
99
|
+
var webConfig = {};
|
|
100
|
+
webConfig.hostname = hostname;
|
|
101
|
+
webConfig.port = port;
|
|
102
|
+
webConfig.protocol = protocol;
|
|
103
|
+
//webConfig.path = null;
|
|
104
|
+
webConfig.proxyTimeout = 120000;
|
|
105
|
+
webConfig.proxyName = "Cloud CMS UI Proxy";
|
|
106
|
+
webConfig.onReq = function(req, options) {
|
|
107
|
+
|
|
108
|
+
if (!options.headers) {
|
|
109
|
+
options.headers = {};
|
|
125
110
|
}
|
|
126
|
-
|
|
111
|
+
var headers = options.headers;
|
|
127
112
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
113
|
+
if (options.path && options.path.startsWith("/proxy")) {
|
|
114
|
+
options.path = options.path.substring(6);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (pathPrefix) {
|
|
118
|
+
options.path = path.join(pathPrefix, options.path);
|
|
131
119
|
}
|
|
132
|
-
catch (e) { }
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
// if we're using auth credentials that are picked up in SSO chain, then we listen for a 401
|
|
136
|
-
// and if we hear it, we automatically invalidate the SSO chain so that the next request
|
|
137
|
-
// will continue to work
|
|
138
|
-
proxyServer.on("proxyRes", function (proxyRes, req, res) {
|
|
139
120
|
|
|
140
|
-
|
|
121
|
+
// used to auto-assign the client header for /oauth/token requests
|
|
122
|
+
oauth2.autoProxy(req);
|
|
123
|
+
|
|
124
|
+
// copy domain host into "x-cloudcms-domainhost"
|
|
125
|
+
if (req.domainHost) {
|
|
126
|
+
headers["x-cloudcms-domainhost"] = req.domainHost; // this could be "localhost"
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// copy virtual host into "x-cloudcms-virtualhost"
|
|
130
|
+
if (req.virtualHost) {
|
|
131
|
+
headers["x-cloudcms-virtualhost"] = req.virtualHost; // this could be "root.cloudcms.net" or "abc.cloudcms.net"
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// copy deployment descriptor info
|
|
135
|
+
if (req.descriptor)
|
|
136
|
+
{
|
|
137
|
+
if (req.descriptor.tenant)
|
|
138
|
+
{
|
|
139
|
+
if (req.descriptor.tenant.id)
|
|
140
|
+
{
|
|
141
|
+
headers["x-cloudcms-tenant-id"] = req.descriptor.tenant.id;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (req.descriptor.tenant.title)
|
|
145
|
+
{
|
|
146
|
+
headers["x-cloudcms-tenant-title"] = req.descriptor.tenant.title;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
141
149
|
|
|
150
|
+
if (req.descriptor.application)
|
|
151
|
+
{
|
|
152
|
+
if (req.descriptor.application.id)
|
|
153
|
+
{
|
|
154
|
+
headers["x-cloudcms-application-id"] = req.descriptor.application.id;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (req.descriptor.application.title)
|
|
158
|
+
{
|
|
159
|
+
headers["x-cloudcms-application-title"] = req.descriptor.application.title;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// set optional "x-cloudcms-origin" header
|
|
165
|
+
var cloudcmsOrigin = null;
|
|
166
|
+
if (req.virtualHost)
|
|
167
|
+
{
|
|
168
|
+
cloudcmsOrigin = req.virtualHost;
|
|
169
|
+
}
|
|
170
|
+
if (cloudcmsOrigin)
|
|
171
|
+
{
|
|
172
|
+
headers["x-cloudcms-origin"] = cloudcmsOrigin;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// set x-cloudcms-server-version header
|
|
176
|
+
headers["x-cloudcms-server-version"] = process.env.CLOUDCMS_APPSERVER_PACKAGE_VERSION;
|
|
177
|
+
|
|
178
|
+
// keep alive
|
|
179
|
+
//req.headers["connection"] = "keep-alive";
|
|
180
|
+
|
|
181
|
+
// if the incoming request didn't have an "Authorization" header
|
|
182
|
+
// and we have a logged in Gitana User via Auth, then set authorization header to Bearer Access Token
|
|
183
|
+
if (!req.headers["authorization"])
|
|
184
|
+
{
|
|
185
|
+
if (req.gitana_user)
|
|
186
|
+
{
|
|
187
|
+
headers["authorization"] = "Bearer " + req.gitana_user.getDriver().http.accessToken();
|
|
188
|
+
}
|
|
189
|
+
else if (req.gitana_proxy_access_token)
|
|
190
|
+
{
|
|
191
|
+
headers["authorization"] = "Bearer " + req.gitana_proxy_access_token;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
webConfig.onRes = function(req, res, proxyRes) {
|
|
196
|
+
|
|
142
197
|
if (req.gitana_user)
|
|
143
198
|
{
|
|
144
199
|
var chunks = [];
|
|
200
|
+
|
|
145
201
|
// triggers on data receive
|
|
146
202
|
proxyRes.on('data', function(chunk) {
|
|
147
203
|
// add received chunk to chunks array
|
|
@@ -149,8 +205,6 @@ var createProxyHandler = function(proxyTarget, pathPrefix)
|
|
|
149
205
|
});
|
|
150
206
|
|
|
151
207
|
proxyRes.on("end", function () {
|
|
152
|
-
|
|
153
|
-
console.log("proxyRes.end, code: " + proxyRes.statusCode);
|
|
154
208
|
|
|
155
209
|
if (proxyRes.statusCode === 401)
|
|
156
210
|
{
|
|
@@ -160,15 +214,16 @@ var createProxyHandler = function(proxyTarget, pathPrefix)
|
|
|
160
214
|
var identifier = req.identity_properties.provider_id + "/" + req.identity_properties.user_identifier;
|
|
161
215
|
|
|
162
216
|
_LOCK([identifier], function(err, releaseLockFn) {
|
|
163
|
-
|
|
217
|
+
|
|
164
218
|
if (err)
|
|
165
219
|
{
|
|
166
220
|
// failed to acquire lock
|
|
167
221
|
console.log("FAILED TO ACQUIRE LOCK", err);
|
|
168
222
|
req.log("FAILED TO ACQUIRE LOCK", err);
|
|
223
|
+
try { releaseLockFn(); } catch (e) { }
|
|
169
224
|
return;
|
|
170
225
|
}
|
|
171
|
-
|
|
226
|
+
|
|
172
227
|
var cleanup = function (full)
|
|
173
228
|
{
|
|
174
229
|
delete Gitana.APPS[req.identity_properties.token];
|
|
@@ -186,8 +241,7 @@ var createProxyHandler = function(proxyTarget, pathPrefix)
|
|
|
186
241
|
if (err) {
|
|
187
242
|
cleanup(true);
|
|
188
243
|
req.log("Invalidated auth state for gitana user: " + req.identity_properties.token);
|
|
189
|
-
releaseLockFn();
|
|
190
|
-
return;
|
|
244
|
+
return releaseLockFn();
|
|
191
245
|
}
|
|
192
246
|
|
|
193
247
|
req.gitana_user.getDriver().reloadAuthInfo(function () {
|
|
@@ -202,112 +256,92 @@ var createProxyHandler = function(proxyTarget, pathPrefix)
|
|
|
202
256
|
}
|
|
203
257
|
});
|
|
204
258
|
}
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
var proxyHandlerServer = http.createServer(function(req, res) {
|
|
208
|
-
|
|
209
|
-
console.log("proxy.1: " + req.url);
|
|
210
|
-
if (req.headers)
|
|
211
|
-
{
|
|
212
|
-
for (var k in req.headers)
|
|
213
|
-
{
|
|
214
|
-
console.log("proxy.2 header " + k + " = " + req.headers[k]);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
// used to auto-assign the client header for /oauth/token requests
|
|
219
|
-
oauth2.autoProxy(req);
|
|
220
|
-
|
|
221
|
-
// copy domain host into "x-cloudcms-domainhost"
|
|
222
|
-
if (req.domainHost)
|
|
223
|
-
{
|
|
224
|
-
req.headers["x-cloudcms-domainhost"] = req.domainHost; // this could be "localhost"
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
// copy virtual host into "x-cloudcms-virtualhost"
|
|
228
|
-
if (req.virtualHost)
|
|
229
|
-
{
|
|
230
|
-
req.headers["x-cloudcms-virtualhost"] = req.virtualHost; // this could be "root.cloudcms.net" or "abc.cloudcms.net"
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
// copy deployment descriptor info
|
|
234
|
-
if (req.descriptor)
|
|
235
|
-
{
|
|
236
|
-
if (req.descriptor.tenant)
|
|
237
|
-
{
|
|
238
|
-
if (req.descriptor.tenant.id)
|
|
239
|
-
{
|
|
240
|
-
req.headers["x-cloudcms-tenant-id"] = req.descriptor.tenant.id;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
if (req.descriptor.tenant.title)
|
|
244
|
-
{
|
|
245
|
-
req.headers["x-cloudcms-tenant-title"] = req.descriptor.tenant.title;
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
if (req.descriptor.application)
|
|
250
|
-
{
|
|
251
|
-
if (req.descriptor.application.id)
|
|
252
|
-
{
|
|
253
|
-
req.headers["x-cloudcms-application-id"] = req.descriptor.application.id;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
if (req.descriptor.application.title)
|
|
257
|
-
{
|
|
258
|
-
req.headers["x-cloudcms-application-title"] = req.descriptor.application.title;
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
// set optional "x-cloudcms-origin" header
|
|
264
|
-
var cloudcmsOrigin = null;
|
|
265
|
-
if (req.virtualHost)
|
|
266
|
-
{
|
|
267
|
-
cloudcmsOrigin = req.virtualHost;
|
|
268
|
-
}
|
|
269
|
-
if (cloudcmsOrigin)
|
|
270
|
-
{
|
|
271
|
-
req.headers["x-cloudcms-origin"] = cloudcmsOrigin;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
// set x-cloudcms-server-version header
|
|
275
|
-
req.headers["x-cloudcms-server-version"] = process.env.CLOUDCMS_APPSERVER_PACKAGE_VERSION;
|
|
276
|
-
|
|
277
|
-
// keep alive
|
|
278
|
-
req.headers["connection"] = "keep-alive";
|
|
279
|
-
|
|
280
|
-
// if the incoming request didn't have an "Authorization" header
|
|
281
|
-
// and we have a logged in Gitana User via Auth, then set authorization header to Bearer Access Token
|
|
282
|
-
if (!req.headers["authorization"])
|
|
283
|
-
{
|
|
284
|
-
if (req.gitana_user)
|
|
285
|
-
{
|
|
286
|
-
req.headers["authorization"] = "Bearer " + req.gitana_user.getDriver().http.accessToken();
|
|
287
|
-
}
|
|
288
|
-
else if (req.gitana_proxy_access_token)
|
|
289
|
-
{
|
|
290
|
-
req.headers["authorization"] = "Bearer " + req.gitana_proxy_access_token;
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
259
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
260
|
+
//res.setHeader('x-powered-by', 'cloudcms');
|
|
261
|
+
res.writeHead(proxyRes.statusCode, proxyRes.headers)
|
|
262
|
+
proxyRes.pipe(res)
|
|
263
|
+
};
|
|
297
264
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
265
|
+
var proxyRequestHandler = function(req, res) {
|
|
266
|
+
proxy.web(req, res, webConfig, function(err, req, res) {
|
|
267
|
+
defaultWebHandler(err, req, res);
|
|
268
|
+
});
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
// cookie domain rewrite?
|
|
273
|
+
|
|
274
|
+
// // if we're using auth credentials that are picked up in SSO chain, then we listen for a 401
|
|
275
|
+
// // and if we hear it, we automatically invalidate the SSO chain so that the next request
|
|
276
|
+
// // will continue to work
|
|
277
|
+
// proxyServer.on("proxyRes", function (proxyRes, req, res) {
|
|
278
|
+
//
|
|
279
|
+
// console.log("proxyRes.1");
|
|
280
|
+
//
|
|
281
|
+
// if (req.gitana_user)
|
|
282
|
+
// {
|
|
283
|
+
// var chunks = [];
|
|
284
|
+
// // triggers on data receive
|
|
285
|
+
// proxyRes.on('data', function(chunk) {
|
|
286
|
+
// // add received chunk to chunks array
|
|
287
|
+
// chunks.push(chunk);
|
|
288
|
+
// });
|
|
289
|
+
//
|
|
290
|
+
// proxyRes.on("end", function () {
|
|
291
|
+
//
|
|
292
|
+
// console.log("proxyRes.end, code: " + proxyRes.statusCode);
|
|
293
|
+
//
|
|
294
|
+
// if (proxyRes.statusCode === 401)
|
|
295
|
+
// {
|
|
296
|
+
// var text = "" + Buffer.concat(chunks);
|
|
297
|
+
// if (text && (text.indexOf("invalid_token") > -1) || (text.indexOf("invalid_grant") > -1))
|
|
298
|
+
// {
|
|
299
|
+
// var identifier = req.identity_properties.provider_id + "/" + req.identity_properties.user_identifier;
|
|
300
|
+
//
|
|
301
|
+
// _LOCK([identifier], function(err, releaseLockFn) {
|
|
302
|
+
//
|
|
303
|
+
// if (err)
|
|
304
|
+
// {
|
|
305
|
+
// // failed to acquire lock
|
|
306
|
+
// console.log("FAILED TO ACQUIRE LOCK", err);
|
|
307
|
+
// req.log("FAILED TO ACQUIRE LOCK", err);
|
|
308
|
+
// return;
|
|
309
|
+
// }
|
|
310
|
+
//
|
|
311
|
+
// var cleanup = function (full)
|
|
312
|
+
// {
|
|
313
|
+
// delete Gitana.APPS[req.identity_properties.token];
|
|
314
|
+
// delete Gitana.PLATFORM_CACHE[req.identity_properties.token];
|
|
315
|
+
//
|
|
316
|
+
// if (full) {
|
|
317
|
+
// auth.removeUserCacheEntry(identifier);
|
|
318
|
+
// }
|
|
319
|
+
// };
|
|
320
|
+
//
|
|
321
|
+
// // null out the access token
|
|
322
|
+
// // this will force the refresh token to be used to get a new one on the next request
|
|
323
|
+
// req.gitana_user.getDriver().http.refresh(function (err) {
|
|
324
|
+
//
|
|
325
|
+
// if (err) {
|
|
326
|
+
// cleanup(true);
|
|
327
|
+
// req.log("Invalidated auth state for gitana user: " + req.identity_properties.token);
|
|
328
|
+
// releaseLockFn();
|
|
329
|
+
// return;
|
|
330
|
+
// }
|
|
331
|
+
//
|
|
332
|
+
// req.gitana_user.getDriver().reloadAuthInfo(function () {
|
|
333
|
+
// cleanup(true);
|
|
334
|
+
// req.log("Refreshed token for gitana user: " + req.identity_properties.token);
|
|
335
|
+
// releaseLockFn();
|
|
336
|
+
// });
|
|
337
|
+
// });
|
|
338
|
+
// });
|
|
339
|
+
// }
|
|
340
|
+
//
|
|
341
|
+
// }
|
|
342
|
+
// });
|
|
343
|
+
// }
|
|
344
|
+
// });
|
|
311
345
|
|
|
312
|
-
return
|
|
346
|
+
return proxyRequestHandler;
|
|
313
347
|
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
package-lock.json binary
|