Socket
Socket
Sign inDemoInstall

ewd-feder8

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.1 to 1.1.0

79

lib/worker.js

@@ -27,4 +27,7 @@ /*

25 July 2016
Thanks to Ward De Backer for enhancements and bug fixes
*/
var url = require('url'); // use url module to parse the host part
var request = require('request');

@@ -43,18 +46,35 @@ var sessions = require('ewd-session');

var group = this.userDefined['ewd-feder8'].destination[destination];
var combinedResults = {};
var combinedResponse = {};
var count = 0;
var max = group.length;
group.forEach(function(destination) {
if (this.userDefined['ewd-feder8'].server && this.userDefined['ewd-feder8'].server[destination]) {
var fin = function(results) {
combinedResults[destination] = results;
count++;
if (count === max) finished(combinedResults);
var q = this;
var groupError = ''; // error for undefined servers in group
var params = { // params for emit (messageObj added for use in event handlers, e.g. you need the application property)
destination: destination,
error: groupError, // contains the last undefined server
messageObj: messageObj,
responseObj: combinedResponse,
finished: finished,
forward: forward
};
group.forEach(function(server) {
// defined fin separately to add combining stuff and emit event
var fin = function(response) {
combinedResponse[server] = response;
count++;
if (count === max) {
q.emit('feder8-combined-response', params);
//console.log('**** sendToGroup end: ', params.responseObj);
if (params.responseObj && params.responseObj.responseSent) return;
finished(params.responseObj);
}
sendToHost.call(this, destination, messageObj, fin, forward);
}
if (this.userDefined['ewd-feder8'].server && this.userDefined['ewd-feder8'].server[server]) {
sendToHost.call(this, server, messageObj, fin, forward);
}
else {
combinedResults[destination] = {error: 'Server ' + destination + ' not defined'};
count++;
if (count === max) finished(combinedResults);
groupError = 'Server ' + server + ' not defined';
fin({error: groupError});
}

@@ -64,17 +84,19 @@ }, this);

function sendToHost(destination, messageObj, finished, forward) {
var url = this.userDefined['ewd-feder8'].server[destination].host;
if (!url) {
finished({error: 'host URL not defined for destination ' + destination});
function sendToHost(server, messageObj, finished, forward) {
var hostUrl = this.userDefined['ewd-feder8'].server[server].host;
if (!hostUrl) {
finished({error: 'host URL not defined for destination ' + server});
return;
}
var path = messageObj.params['0'];
if (url.slice(-1) !== '/') url = url + '/';
url = url + path;
if (hostUrl.slice(-1) !== '/') hostUrl = hostUrl + '/';
hostUrl = hostUrl + path;
// preserve original headers, just replace host property
var headers = messageObj.headers || {};
if (headers.host) headers.host = url.parse(hostUrl).host;
headers['content-type'] = headers['content-type'] || 'application/json'; // default to json content-type
var options = {
url: url,
url: hostUrl,
method: messageObj.method,
headers: {
'Content-type': messageObj.headers['content-type']
}
headers: headers
};

@@ -88,4 +110,5 @@ messageObj.handled = true;

var params = {
destination: destination,
destination: server,
error: error,
messageObj: messageObj, // also added messageObj here to know context in response event handler
responseObj: response,

@@ -97,2 +120,3 @@ body: body,

q.emit('feder8-response', params);
if (params.responseObj && params.responseObj.responseSent) return; // if request error, response can be undefined
if (response.responseSent) return;

@@ -115,2 +139,3 @@ if (error) {

'ewd-feder8': function(messageObj, finished) {
var error;
//console.log('*** ewd-feder8 - handling ' + JSON.stringify(messageObj));

@@ -121,5 +146,11 @@ if (!extensionModule && this.userDefined['ewd-feder8'] && this.userDefined['ewd-feder8'].extensionModule) {

extensionModule.call(this);
//console.log('*** extension module called');
}
catch(err) {
finished({error: 'Unable to load extension module ' + this.userDefined['ewd-feder8'].extensionModule});
error = 'Unable to load extension module ' + this.userDefined['ewd-feder8'].extensionModule;
console.log(error + ': ' + err); // add detailed logging to console + reason in response
finished({
error: error,
reason: err
});
return;

@@ -126,0 +157,0 @@ }

{
"name": "ewd-feder8",
"version": "1.0.1",
"version": "1.1.0",
"description": "ewd-xpress based module for federated HTTP/REST service",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -15,3 +15,3 @@ # ewd-feder8: ewd-xpress based module for federated HTTP/REST service

For more informaation on ewd-feder8:
For more information on ewd-feder8:

@@ -18,0 +18,0 @@ [http://gradvs1.mgateway.com/download/ewd-feder8.pdf](http://gradvs1.mgateway.com/download/ewd-feder8.pdf)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc