Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proxy fixes #93

Merged
merged 1 commit into from Apr 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 19 additions & 10 deletions lib/proxy.js
Expand Up @@ -84,17 +84,26 @@ function makeSimpleProxy(host, port, options, pluginID, serviceName) {
const headers = res2.headers;
for (const header of Object.keys(headers)) {
if (header == 'location') {
var pattern = /^http.+\/ZLUX\/plugins\/.+/;
const location = headers[header];
let pattern = /^http.+\/ZLUX\/plugins\/.+/;
if (!pattern.test(headers[header])) {
/* Find :{port} and take all that is after */
var x = headers[header];
var y = x.split(":");
var z = y[2];
var t = z.indexOf('/');
var newEnd = z.substring(t);
var newRedirect = req1.protocol + '://' + req1.get('host') + "/ZLUX/plugins/" + pluginID + "/services/" + serviceName + newEnd;
proxyLog.debug('Redirecting to: ' + newRedirect);
res1.set(header, newRedirect);
if (location.startsWith('/')) {
res1.set(header, `${req1.protocol}://${req1.get('host')}/ZLUX/plugins/${pluginID}/services/${serviceName}/_current${location}`);
}
else if (location.startsWith('http')) {
const locationParts = location.split(":");
let part;
if (locationParts.length > 2) {
part = locationParts[2];
} else {
part = locationParts[1]
}
const t = part.indexOf('/');
const newEnd = part.substring(t);
const newRedirect = req1.protocol + '://' + req1.get('host') + "/ZLUX/plugins/" + pluginID + "/services/_current" + serviceName + newEnd;
proxyLog.debug('Redirecting to: ' + newRedirect);
res1.set(header, newRedirect);
}
}
}
else {
Expand Down
22 changes: 13 additions & 9 deletions lib/webapp.js
Expand Up @@ -1002,20 +1002,22 @@ WebApp.prototype = {
installErrorHanders() {
this.expressApp.use((req, res, next) => {
const headers = req.headers
let referrerPresent = false;
for (const header of Object.keys(headers)) {
/* Try to find a referer header and try to
* redirect to our server,
*/
if (header == 'referer') {
referrerPresent = true;
let referrer = headers[header];
var pattern = new RegExp('^http.+\/'+this.options.productCode+'\/plugins\/.+');
if (pattern.test(referrer)) {
var parts = headers[header].split("/");
var zluxIndex = parts.indexOf(this.options.productCode);
var pluginID = parts[zluxIndex + 2];
var serviceName = parts[zluxIndex + 4];
var myProxy = proxyMap.get(pluginID + ":" + serviceName);
var fullUrl = req.originalUrl;
const parts = headers[header].split("/");
const zluxIndex = parts.indexOf(this.options.productCode);
const pluginID = parts[zluxIndex + 2];
const serviceName = parts[zluxIndex + 4];
const myProxy = proxyMap.get(pluginID + ":" + serviceName);
const fullUrl = req.originalUrl;
req.url = fullUrl;
if (myProxy != undefined) {
utilLog.debug("About to call myProxy");
Expand All @@ -1032,11 +1034,13 @@ WebApp.prototype = {
+ ` 404 because referrer (${referrer}) didn't match a plugin pattern`);
return do404(req.url, res, this.options.productCode + ": unknown resource requested");
}
} else {
return do404(req.url, res, this.options.productCode
+ ": unknown resource requested");
break;
}
}
if (!referrerPresent) {
return do404(req.url, res, this.options.productCode
+ ": unknown resource requested");
}
});
}
};
Expand Down