cloudcms-server 0.9.276 → 3.2.279
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 +11 -21
- package/package.json +4 -5
- package/util/proxy-factory.js +211 -181
- 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
|
|
|
@@ -235,16 +225,16 @@ exports = module.exports = function()
|
|
|
235
225
|
}
|
|
236
226
|
|
|
237
227
|
// caching scenario
|
|
238
|
-
|
|
239
|
-
//
|
|
240
|
-
// if (!err && readStream)
|
|
241
|
-
// {
|
|
242
|
-
// return util.sendFile(res, readStream, function (err) {
|
|
243
|
-
// // done!
|
|
244
|
-
// });
|
|
245
|
-
// }
|
|
228
|
+
_handleCacheRead(req, function (err, readStream) {
|
|
246
229
|
|
|
247
|
-
|
|
230
|
+
if (!err && readStream)
|
|
231
|
+
{
|
|
232
|
+
return util.sendFile(res, readStream, function (err) {
|
|
233
|
+
// done!
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
_handleWrapCacheWriter(req, res, function(err) {
|
|
248
238
|
|
|
249
239
|
// acquire the proxy handler
|
|
250
240
|
var proxyTarget = req.gitanaConfig.baseURL;
|
|
@@ -261,8 +251,8 @@ exports = module.exports = function()
|
|
|
261
251
|
|
|
262
252
|
proxyHandler(req, res);
|
|
263
253
|
});
|
|
264
|
-
|
|
265
|
-
|
|
254
|
+
});
|
|
255
|
+
});
|
|
266
256
|
}
|
|
267
257
|
else
|
|
268
258
|
{
|
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.279",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
12
|
"url": "git://github.com/gitana/cloudcms-server.git"
|
|
@@ -40,10 +40,12 @@
|
|
|
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",
|
|
48
|
+
"http2-proxy": "^5.0.53",
|
|
47
49
|
"install": "^0.13.0",
|
|
48
50
|
"ioredis": "4.28.5",
|
|
49
51
|
"json5": "^1.0.1",
|
|
@@ -92,10 +94,7 @@
|
|
|
92
94
|
"uuid": "^3.3.2",
|
|
93
95
|
"vm2": "^3.8.4",
|
|
94
96
|
"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"
|
|
97
|
+
"winston": "^3.3.3"
|
|
99
98
|
},
|
|
100
99
|
"contributors": [
|
|
101
100
|
{
|
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,88 +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
|
-
"timeout": process.defaultHttpTimeoutMs,
|
|
91
|
-
//"changeOrigin": true
|
|
92
|
-
"headers": {
|
|
93
|
-
"host": proxyHost
|
|
94
|
-
},
|
|
95
|
-
"cookieDomainRewrite": true
|
|
82
|
+
finalhandler(req, res)(err);
|
|
96
83
|
};
|
|
97
|
-
|
|
98
|
-
// use https?
|
|
99
|
-
if (util.isHttps(proxyTarget))
|
|
100
|
-
{
|
|
101
|
-
proxyConfig = {
|
|
102
|
-
"target": proxyTarget,
|
|
103
|
-
"agent": https.globalAgent,
|
|
104
|
-
"xfwd": false,
|
|
105
|
-
"proxyTimeout": process.defaultHttpTimeoutMs,
|
|
106
|
-
"timeout": process.defaultHttpTimeoutMs,
|
|
107
|
-
"headers": {
|
|
108
|
-
"host": proxyHost
|
|
109
|
-
},
|
|
110
|
-
"cookieDomainRewrite": true
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
84
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
//
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
//
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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 = {};
|
|
129
110
|
}
|
|
130
|
-
|
|
111
|
+
var headers = options.headers;
|
|
131
112
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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);
|
|
135
119
|
}
|
|
136
|
-
catch (e) { }
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
// if we're using auth credentials that are picked up in SSO chain, then we listen for a 401
|
|
140
|
-
// and if we hear it, we automatically invalidate the SSO chain so that the next request
|
|
141
|
-
// will continue to work
|
|
142
|
-
proxyServer.on("proxyRes", function (proxyRes, req, res) {
|
|
143
120
|
|
|
144
|
-
|
|
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
|
+
}
|
|
145
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
|
+
|
|
146
197
|
if (req.gitana_user)
|
|
147
198
|
{
|
|
148
199
|
var chunks = [];
|
|
200
|
+
|
|
149
201
|
// triggers on data receive
|
|
150
202
|
proxyRes.on('data', function(chunk) {
|
|
151
203
|
// add received chunk to chunks array
|
|
@@ -153,8 +205,6 @@ var createProxyHandler = function(proxyTarget, pathPrefix)
|
|
|
153
205
|
});
|
|
154
206
|
|
|
155
207
|
proxyRes.on("end", function () {
|
|
156
|
-
|
|
157
|
-
console.log("proxyRes.end, code: " + proxyRes.statusCode);
|
|
158
208
|
|
|
159
209
|
if (proxyRes.statusCode === 401)
|
|
160
210
|
{
|
|
@@ -164,15 +214,16 @@ var createProxyHandler = function(proxyTarget, pathPrefix)
|
|
|
164
214
|
var identifier = req.identity_properties.provider_id + "/" + req.identity_properties.user_identifier;
|
|
165
215
|
|
|
166
216
|
_LOCK([identifier], function(err, releaseLockFn) {
|
|
167
|
-
|
|
217
|
+
|
|
168
218
|
if (err)
|
|
169
219
|
{
|
|
170
220
|
// failed to acquire lock
|
|
171
221
|
console.log("FAILED TO ACQUIRE LOCK", err);
|
|
172
222
|
req.log("FAILED TO ACQUIRE LOCK", err);
|
|
223
|
+
try { releaseLockFn(); } catch (e) { }
|
|
173
224
|
return;
|
|
174
225
|
}
|
|
175
|
-
|
|
226
|
+
|
|
176
227
|
var cleanup = function (full)
|
|
177
228
|
{
|
|
178
229
|
delete Gitana.APPS[req.identity_properties.token];
|
|
@@ -190,8 +241,7 @@ var createProxyHandler = function(proxyTarget, pathPrefix)
|
|
|
190
241
|
if (err) {
|
|
191
242
|
cleanup(true);
|
|
192
243
|
req.log("Invalidated auth state for gitana user: " + req.identity_properties.token);
|
|
193
|
-
releaseLockFn();
|
|
194
|
-
return;
|
|
244
|
+
return releaseLockFn();
|
|
195
245
|
}
|
|
196
246
|
|
|
197
247
|
req.gitana_user.getDriver().reloadAuthInfo(function () {
|
|
@@ -206,112 +256,92 @@ var createProxyHandler = function(proxyTarget, pathPrefix)
|
|
|
206
256
|
}
|
|
207
257
|
});
|
|
208
258
|
}
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
var proxyHandlerServer = http.createServer(function(req, res) {
|
|
212
|
-
|
|
213
|
-
console.log("proxy.1: " + req.url);
|
|
214
|
-
if (req.headers)
|
|
215
|
-
{
|
|
216
|
-
for (var k in req.headers)
|
|
217
|
-
{
|
|
218
|
-
console.log("proxy.2 header " + k + " = " + req.headers[k]);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
// used to auto-assign the client header for /oauth/token requests
|
|
223
|
-
oauth2.autoProxy(req);
|
|
224
|
-
|
|
225
|
-
// copy domain host into "x-cloudcms-domainhost"
|
|
226
|
-
if (req.domainHost)
|
|
227
|
-
{
|
|
228
|
-
req.headers["x-cloudcms-domainhost"] = req.domainHost; // this could be "localhost"
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
// copy virtual host into "x-cloudcms-virtualhost"
|
|
232
|
-
if (req.virtualHost)
|
|
233
|
-
{
|
|
234
|
-
req.headers["x-cloudcms-virtualhost"] = req.virtualHost; // this could be "root.cloudcms.net" or "abc.cloudcms.net"
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
// copy deployment descriptor info
|
|
238
|
-
if (req.descriptor)
|
|
239
|
-
{
|
|
240
|
-
if (req.descriptor.tenant)
|
|
241
|
-
{
|
|
242
|
-
if (req.descriptor.tenant.id)
|
|
243
|
-
{
|
|
244
|
-
req.headers["x-cloudcms-tenant-id"] = req.descriptor.tenant.id;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
if (req.descriptor.tenant.title)
|
|
248
|
-
{
|
|
249
|
-
req.headers["x-cloudcms-tenant-title"] = req.descriptor.tenant.title;
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
if (req.descriptor.application)
|
|
254
|
-
{
|
|
255
|
-
if (req.descriptor.application.id)
|
|
256
|
-
{
|
|
257
|
-
req.headers["x-cloudcms-application-id"] = req.descriptor.application.id;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
if (req.descriptor.application.title)
|
|
261
|
-
{
|
|
262
|
-
req.headers["x-cloudcms-application-title"] = req.descriptor.application.title;
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
// set optional "x-cloudcms-origin" header
|
|
268
|
-
var cloudcmsOrigin = null;
|
|
269
|
-
if (req.virtualHost)
|
|
270
|
-
{
|
|
271
|
-
cloudcmsOrigin = req.virtualHost;
|
|
272
|
-
}
|
|
273
|
-
if (cloudcmsOrigin)
|
|
274
|
-
{
|
|
275
|
-
req.headers["x-cloudcms-origin"] = cloudcmsOrigin;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
// set x-cloudcms-server-version header
|
|
279
|
-
req.headers["x-cloudcms-server-version"] = process.env.CLOUDCMS_APPSERVER_PACKAGE_VERSION;
|
|
280
|
-
|
|
281
|
-
// keep alive
|
|
282
|
-
req.headers["connection"] = "keep-alive";
|
|
283
|
-
|
|
284
|
-
// if the incoming request didn't have an "Authorization" header
|
|
285
|
-
// and we have a logged in Gitana User via Auth, then set authorization header to Bearer Access Token
|
|
286
|
-
if (!req.headers["authorization"])
|
|
287
|
-
{
|
|
288
|
-
if (req.gitana_user)
|
|
289
|
-
{
|
|
290
|
-
req.headers["authorization"] = "Bearer " + req.gitana_user.getDriver().http.accessToken();
|
|
291
|
-
}
|
|
292
|
-
else if (req.gitana_proxy_access_token)
|
|
293
|
-
{
|
|
294
|
-
req.headers["authorization"] = "Bearer " + req.gitana_proxy_access_token;
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
259
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
260
|
+
//res.setHeader('x-powered-by', 'cloudcms');
|
|
261
|
+
res.writeHead(proxyRes.statusCode, proxyRes.headers)
|
|
262
|
+
proxyRes.pipe(res)
|
|
263
|
+
};
|
|
301
264
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
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
|
+
// });
|
|
315
345
|
|
|
316
|
-
return
|
|
346
|
+
return proxyRequestHandler;
|
|
317
347
|
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
package-lock.json binary
|