express-http-proxy
Advanced tools
Comparing version 1.0.3 to 1.0.4
{ | ||
"name": "express-http-proxy", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "http proxy middleware for express", | ||
@@ -5,0 +5,0 @@ "engines": { |
@@ -50,4 +50,5 @@ # express-http-proxy [![NPM version](https://badge.fury.io/js/express-http-proxy.svg)](http://badge.fury.io/js/express-http-proxy) [![Build Status](https://travis-ci.org/villadora/express-http-proxy.svg?branch=master)](https://travis-ci.org/villadora/express-http-proxy) [![Dependency Status](https://gemnasium.com/villadora/express-http-proxy.svg)](https://gemnasium.com/villadora/express-http-proxy) | ||
return new Promise(function (resolve, reject) { | ||
setTimeout(function () { // do asyncness | ||
resolve(fancyResults); | ||
setTimeout(function () { // simulate async | ||
var resolvedPathValue = "http://google.com"; | ||
resolve(resolvedPathValue); | ||
}, 200); | ||
@@ -171,6 +172,8 @@ }); | ||
You can mutate the request options before sending the proxyRequest. | ||
You can override most request options before issuing the proxyRequest. | ||
proxyReqOpt represents the options argument passed to the (http|https).request | ||
module. | ||
NOTE: req.path cannot be changed via this method; use ```proxyReqPathResolver``` instead. (see https://github.com/villadora/express-http-proxy/issues/243) | ||
```js | ||
@@ -183,4 +186,2 @@ app.use('/proxy', proxy('www.google.com', { | ||
proxyReqOpts.method = 'GET'; | ||
// you could change the path | ||
proxyReqOpts.path = 'http://dev/null' | ||
return proxyReqOpts; | ||
@@ -388,7 +389,7 @@ } | ||
You can use the ability to decorate the proxy request prior to sending. See ```proxyReqOptDecorators``` for more details. | ||
You can use the ability to decorate the proxy request prior to sending. See ```proxyReqOptDecorator``` for more details. | ||
```js | ||
app.use('/', proxy('internalhost.example.com', { | ||
proxyReqOptDecorators: function(proxyReqOpts, originalReq) { | ||
proxyReqOptDecorator: function(proxyReqOpts, originalReq) { | ||
proxyReqOpts.ca = [caCert, intermediaryCert] | ||
@@ -406,2 +407,3 @@ return proxyReqOpts; | ||
| --- | --- | | ||
| 1.0.4 | Minor documentation, test, and package fixes | | ||
| 1.0.3 | Fixes 'limit option is not taken into account | | ||
@@ -408,0 +410,0 @@ | 1.0.2 | Minor docs corrections. | |
@@ -5,4 +5,5 @@ var express = require('express'); | ||
var startProxyTarget = require('./support/proxyTarget'); | ||
var expect = require('chai').expect; | ||
describe('uses remote path', function () { | ||
describe('uses remote path', function() { | ||
'use strict'; | ||
@@ -13,35 +14,41 @@ | ||
var app = express(); | ||
it('does nothing', function (done) { | ||
var proxyRouteFn = [{ | ||
method: 'get', | ||
path: '/somePath', | ||
fn: function(req, res) { | ||
debugger; | ||
res.sendStatus(200); | ||
} | ||
}]; | ||
startProxyTarget(8309, 1000, proxyRouteFn); | ||
app.use('/somePath', proxy('http://localhost:8309/other/path')); | ||
var proxyRoutes = ['/somePath/', '/somePath/longer/path', '/somePath/long/path/with/many/tokens']; | ||
var proxyKeyPath = '/somePath'; | ||
var server; | ||
request(app) | ||
.get('/somePath/abc') | ||
.end(function(err) { | ||
debugger; | ||
if (err) { | ||
return done(err); | ||
} | ||
done(); | ||
}); | ||
afterEach(function() { | ||
server.close(); | ||
}); | ||
//So that when I call /somePath/abc, it is proxied to http://other.server/other/path/abc? | ||
//Right now, I have to workaround with something like: | ||
proxyRoutes.forEach(function(path) { | ||
it('uses path component from inbound request', function(done) { | ||
//const proxyPath = url.parse('http://other.server/other/path').path; | ||
//app.use('/somePath', proxy('http://other.server/other/path', { | ||
//proxyReqPathResolver(req) { | ||
//const reqPath = url.parse(req.url).path; | ||
//return [proxyPath, reqPath].join('/'); | ||
//} | ||
//})); | ||
var modifiedPath = path.replace(new RegExp(proxyKeyPath), ''); | ||
var proxyRouteFn = { | ||
method: 'get', | ||
path: modifiedPath, | ||
fn: function(req, res) { | ||
res.json({path: path, modifiedPath: modifiedPath}); | ||
} | ||
}; | ||
server = startProxyTarget(8309, 1000, [proxyRouteFn]); | ||
app.use('/somePath/', proxy('http://localhost:8309')); | ||
request(app) | ||
.get(path) | ||
.expect(200) | ||
.end(function(err, response) { | ||
if (err) { | ||
return done(err); | ||
} | ||
expect(response.path === path); | ||
expect(response.modifiedPath === path); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
@@ -48,0 +55,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1617
423
74543
43