From 911c2f13720a8f0b90a798af2c25d107e5415063 Mon Sep 17 00:00:00 2001 From: Roarke Gaskill Date: Mon, 9 Jun 2014 20:08:46 -0500 Subject: [PATCH] proxy url normalization more simple --- lib/middleware/proxy.js | 1 + test/unit/middleware/proxy.spec.coffee | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/middleware/proxy.js b/lib/middleware/proxy.js index 55f599a0d..95491ccc4 100644 --- a/lib/middleware/proxy.js +++ b/lib/middleware/proxy.js @@ -24,6 +24,7 @@ var parseProxyConfig = function(proxies) { if (endsWithSlash(proxyPath) && !endsWithSlash(proxyUrl)) { log.warn('proxy "%s" normalized to "%s"', proxyUrl, proxyUrl + '/'); proxyUrl += '/'; + pathname += '/'; } if (!endsWithSlash(proxyPath) && endsWithSlash(proxyUrl)) { diff --git a/test/unit/middleware/proxy.spec.coffee b/test/unit/middleware/proxy.spec.coffee index 907be4583..8cbddc337 100644 --- a/test/unit/middleware/proxy.spec.coffee +++ b/test/unit/middleware/proxy.spec.coffee @@ -154,5 +154,20 @@ describe 'middleware.proxy', -> baseProxyUrl: '/proxy/test', https:false} } + it 'should normalize proxy url 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 normalize proxy url', -> + proxy = {'/base/': 'http://localhost:8000/proxy/test'} + parsedProxyConfig = m.parseProxyConfig proxy + expect(parsedProxyConfig).to.deep.equal { + '/base/': {host: 'localhost', port: '8000', baseProxyUrl: '/proxy/test/', https:false} + } + it 'should handle empty proxy config', -> expect(m.parseProxyConfig {}).to.deep.equal({})