Skip to content

Commit

Permalink
fix(proxy): Port mixup and infinite loop
Browse files Browse the repository at this point in the history
Derive port from proxy-protocol if present.

Closes #1987
  • Loading branch information
budde377 committed Mar 22, 2016
1 parent 8ef475f commit 05616a2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/middleware/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,15 @@ var parseProxyConfig = function (proxies, config) {

var hostname = proxyDetails.hostname || config.hostname
var protocol = proxyDetails.protocol || config.protocol
var port = proxyDetails.port || config.port ||
(proxyDetails.protocol === 'https:' ? '443' : '80')
var https = proxyDetails.protocol === 'https:'

var port
if (proxyDetails.port) {
port = proxyDetails.port
} else if (proxyDetails.protocol) {
port = proxyDetails.protocol === 'https:' ? '443' : '80'
} else {
port = config.port
}
var changeOrigin = 'changeOrigin' in proxyConfiguration ? proxyConfiguration.changeOrigin : false
var proxy = httpProxy.createProxyServer({
target: {
Expand Down
30 changes: 30 additions & 0 deletions test/unit/middleware/proxy.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,36 @@ describe('middleware.proxy', () => {
expect(parsedProxyConfig[0].proxy).to.exist
})

it('should parse right port of proxy target', () => {
var proxy = { '/w': 'http://krinkle.dev/w' }
var config = {port: 9877, hostname: 'localhost'}
var parsedProxyConfig = m.parseProxyConfig(proxy, config)
expect(parsedProxyConfig).to.have.length(1)
expect(parsedProxyConfig[0]).to.containSubset({
host: 'krinkle.dev',
port: '80',
baseUrl: '/w',
path: '/w',
https: false
})
expect(parsedProxyConfig[0].proxy).to.exist
})

it('should parse right port of proxy target w. https', () => {
var proxy = { '/w': 'https://krinkle.dev/w' }
var config = {port: 9877, hostname: 'localhost'}
var parsedProxyConfig = m.parseProxyConfig(proxy, config)
expect(parsedProxyConfig).to.have.length(1)
expect(parsedProxyConfig[0]).to.containSubset({
host: 'krinkle.dev',
port: '443',
baseUrl: '/w',
path: '/w',
https: true
})
expect(parsedProxyConfig[0].proxy).to.exist
})

it('should normalize proxy url', () => {
var proxy = {'/base/': 'http://localhost:8000/proxy/test'}
var parsedProxyConfig = m.parseProxyConfig(proxy, {})
Expand Down

0 comments on commit 05616a2

Please sign in to comment.