Skip to content

Commit

Permalink
Merge pull request #1007 from karma-runner/fix-proxy
Browse files Browse the repository at this point in the history
fix (proxy): Default to karma port and host
  • Loading branch information
deepak1556 committed Apr 8, 2014
2 parents c054c65 + fc58aa1 commit 337a538
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/middleware/proxy.js
Expand Up @@ -2,6 +2,7 @@ var url = require('url');
var httpProxy = require('http-proxy');

var log = require('../logger').create('proxy');
var constant = require('../constants');

var parseProxyConfig = function(proxies) {
var proxyConfig = {};
Expand Down Expand Up @@ -42,7 +43,12 @@ var parseProxyConfig = function(proxies) {
};

if (!proxyConfig[proxyPath].port) {
proxyConfig[proxyPath].port = proxyConfig[proxyPath].https ? '443' : '80';
if (!proxyConfig[proxyPath].host) {
proxyConfig[proxyPath].host = constant.DEFAULT_HOSTNAME;
proxyConfig[proxyPath].port = constant.DEFAULT_PORT;
} else {
proxyConfig[proxyPath].port = proxyConfig[proxyPath].https ? '443' : '80';
}
}
});

Expand Down
9 changes: 9 additions & 0 deletions test/unit/middleware/proxy.spec.coffee
Expand Up @@ -9,6 +9,7 @@ describe 'middleware.proxy', ->
actualOptions = requestedUrl = response = nextSpy = null

m = loadFile __dirname + '/../../../lib/middleware/proxy.js', {'http-proxy': {}}
c = require('../../../lib/constants')

mockProxy =
on: ->
Expand Down Expand Up @@ -145,5 +146,13 @@ describe 'middleware.proxy', ->
'/base': {host: 'localhost', port: '8000', baseProxyUrl: '', https: true}
}

it 'should handle proxy configs with only basepaths', ->
proxy = {'/base': '/proxy/test'}
parsedProxyConfig = m.parseProxyConfig proxy
expect(parsedProxyConfig).to.deep.equal {
'/base': {host: c.DEFAULT_HOSTNAME, port: c.DEFAULT_PORT,
baseProxyUrl: '/proxy/test', https:false}
}

it 'should handle empty proxy config', ->
expect(m.parseProxyConfig {}).to.deep.equal({})

0 comments on commit 337a538

Please sign in to comment.