Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

commandeer

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

commandeer - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0

example/multiple-backends/application.js

4

example/basic/backend.js

@@ -18,3 +18,3 @@ 'use strict';

'<li><a href="/json">Regular JSON</a></li>',
'<li><a href="/json-commandeer">JSON which will be commandeered</a></li>',
'<li><a href="/jsonc">Commandeerable JSON</a></li>',
'</ul>'

@@ -40,3 +40,3 @@ ].join(''));

// JSON which will be commandeered
'/json-commandeer': function (request, response) {
'/jsonc': function (request, response) {
response.writeHead(200, {

@@ -43,0 +43,0 @@ 'Content-Type': 'application/x-commandeer+json'

@@ -6,3 +6,3 @@ 'use strict';

var createResponseInterceptor = require('./response-interceptor');
var url = require('url');
var parseUrl = require('url').parse;

@@ -51,3 +51,3 @@ module.exports = commandeer;

proxy.web(request, response, {
target: options.target
target: resolveTarget(options.target, request)
});

@@ -59,3 +59,3 @@ };

if (options.rewriteHostHeader) {
proxyRequest.setHeader('Host', url.parse(proxyOptions.target).host);
proxyRequest.setHeader('Host', parseUrl(proxyOptions.target).host);
}

@@ -73,2 +73,6 @@ }

function resolveTarget (target, request) {
return (typeof target === 'function' ? target(request) : target);
}
function defaultOptions (options) {

@@ -75,0 +79,0 @@ options = _.defaults({}, options, commandeer.defaults);

{
"name": "commandeer",
"version": "0.3.0",
"version": "0.4.0",

@@ -21,3 +21,3 @@ "description": "Proxy requests through connect and capture JSON responses before they are output",

"dependencies": {
"http-proxy": "~1.8",
"http-proxy": "~1.10",
"underscore": "~1.8"

@@ -31,4 +31,4 @@ },

"mockery": "~1.4",
"proclaim": "~3.1",
"request": "~2.53",
"proclaim": "~3.2",
"request": "~2.55",
"sinon": "~1.14"

@@ -35,0 +35,0 @@ },

@@ -7,3 +7,3 @@

**Current Version:** *0.3.0*
**Current Version:** *0.4.0*
**Node Support:** *0.10.x, 0.12.x*

@@ -139,6 +139,8 @@ **License:** [MIT][mit]

#### `target` (string)
#### `target` (string|function)
The proxy target for the application. This should point to your back-end application which can serve both regular responses and proxy data reponses to be captured by `Content-Type`.
If `target` is a function, it will be called with a request object which can be used to decide on a target. This function must return a string.
Defaults to `'http://localhost'`.

@@ -168,3 +170,11 @@

#### Multiple Backends Example
Proxying to multiple backends from the same application, by using a target function rather than a string.
```
foreman start -d example/multiple-backends
```
Contributing

@@ -171,0 +181,0 @@ ------------

@@ -76,2 +76,9 @@ /* jshint maxstatements: false, maxlen: false */

it('should default the options', function () {
assert.isTrue(underscore.defaults.calledOnce);
assert.deepEqual(underscore.defaults.firstCall.args[0], {});
assert.strictEqual(underscore.defaults.firstCall.args[1], options);
assert.strictEqual(underscore.defaults.firstCall.args[2], commandeer.defaults);
});
it('should create a proxy server', function () {

@@ -114,9 +121,2 @@ assert.isTrue(httpProxy.createProxyServer.calledOnce);

it('should default the options', function () {
assert.isTrue(underscore.defaults.calledOnce);
assert.deepEqual(underscore.defaults.firstCall.args[0], {});
assert.strictEqual(underscore.defaults.firstCall.args[1], options);
assert.strictEqual(underscore.defaults.firstCall.args[2], commandeer.defaults);
});
it('should return a function', function () {

@@ -281,2 +281,38 @@ assert.isFunction(middleware);

describe('commandeer() with a function `target` option', function () {
var options, middleware, proxyServer;
beforeEach(function () {
options = {
contentType: 'application/x-commandeer-unit+json',
dataProperty: 'proxyDataUnit',
rewriteHostHeader: true,
target: sinon.stub().returns('http://localhost:1234')
};
middleware = commandeer(options);
proxyServer = httpProxy.createProxyServer.defaultBehavior.returnValue;
});
describe('returnedFunction()', function () {
var request, response, next;
beforeEach(function () {
request = new http.ClientRequest();
response = new http.ServerResponse();
next = sinon.spy();
middleware(request, response, next);
});
it('should call `options.target` with the request object', function () {
assert.isTrue(options.target.withArgs(request).calledOnce);
});
it('should call `proxyServer.web` with a target set to the return value of `options.target`', function () {
assert.strictEqual(proxyServer.web.firstCall.args[2].target, options.target.firstCall.returnValue);
});
});
});
});
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc