Skip to content

Commit

Permalink
fix(proxy): Pass protocol in target object to enable https requests
Browse files Browse the repository at this point in the history
The protocol parameter is necessary to allow proxying of an HTTPS server.
  • Loading branch information
Richard Herrera committed Oct 20, 2015
1 parent 9aceea1 commit 142db90
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/middleware/proxy.js
Expand Up @@ -35,6 +35,7 @@ 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:'
Expand All @@ -43,7 +44,8 @@ var parseProxyConfig = function (proxies, config) {
target: {
host: hostname,
port: port,
https: https
https: https,
protocol: protocol
},
xfwd: true,
secure: config.proxyValidateSSL
Expand Down
16 changes: 15 additions & 1 deletion test/unit/middleware/proxy.spec.js
Expand Up @@ -166,7 +166,7 @@ describe('middleware.proxy', () => {
expect(parsedProxyConfig[0].proxy).to.exist
})

it('should set defualt https port', () => {
it('should set default https port', () => {
var proxy = {'/base/': 'https://localhost/'}
var parsedProxyConfig = m.parseProxyConfig(proxy, {})
expect(parsedProxyConfig).to.have.length(1)
Expand All @@ -178,6 +178,13 @@ describe('middleware.proxy', () => {
https: true
})
expect(parsedProxyConfig[0].proxy).to.exist
expect(parsedProxyConfig[0].proxy).to.containSubset({
options: {
target: {
protocol: 'https:'
}
}
})
})

it('should handle proxy configs with paths', () => {
Expand Down Expand Up @@ -206,6 +213,13 @@ describe('middleware.proxy', () => {
https: true
})
expect(parsedProxyConfig[0].proxy).to.exist
expect(parsedProxyConfig[0].proxy).to.containSubset({
options: {
target: {
protocol: 'https:'
}
}
})
})

it('should handle proxy configs with only basepaths', () => {
Expand Down

0 comments on commit 142db90

Please sign in to comment.