File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -40,10 +40,15 @@ var parseProxyConfig = function (proxies, config) {
4040
4141 var hostname = proxyDetails . hostname || config . hostname
4242 var protocol = proxyDetails . protocol || config . protocol
43- var port = proxyDetails . port || config . port ||
44- ( proxyDetails . protocol === 'https:' ? '443' : '80' )
4543 var https = proxyDetails . protocol === 'https:'
46-
44+ var port
45+ if ( proxyDetails . port ) {
46+ port = proxyDetails . port
47+ } else if ( proxyDetails . protocol ) {
48+ port = proxyDetails . protocol === 'https:' ? '443' : '80'
49+ } else {
50+ port = config . port
51+ }
4752 var changeOrigin = 'changeOrigin' in proxyConfiguration ? proxyConfiguration . changeOrigin : false
4853 var proxy = httpProxy . createProxyServer ( {
4954 target : {
Original file line number Diff line number Diff line change @@ -253,6 +253,36 @@ describe('middleware.proxy', () => {
253253 expect ( parsedProxyConfig [ 0 ] . proxy ) . to . exist
254254 } )
255255
256+ it ( 'should parse right port of proxy target' , ( ) => {
257+ var proxy = { '/w' : 'http://krinkle.dev/w' }
258+ var config = { port : 9877 , hostname : 'localhost' }
259+ var parsedProxyConfig = m . parseProxyConfig ( proxy , config )
260+ expect ( parsedProxyConfig ) . to . have . length ( 1 )
261+ expect ( parsedProxyConfig [ 0 ] ) . to . containSubset ( {
262+ host : 'krinkle.dev' ,
263+ port : '80' ,
264+ baseUrl : '/w' ,
265+ path : '/w' ,
266+ https : false
267+ } )
268+ expect ( parsedProxyConfig [ 0 ] . proxy ) . to . exist
269+ } )
270+
271+ it ( 'should parse right port of proxy target w. https' , ( ) => {
272+ var proxy = { '/w' : 'https://krinkle.dev/w' }
273+ var config = { port : 9877 , hostname : 'localhost' }
274+ var parsedProxyConfig = m . parseProxyConfig ( proxy , config )
275+ expect ( parsedProxyConfig ) . to . have . length ( 1 )
276+ expect ( parsedProxyConfig [ 0 ] ) . to . containSubset ( {
277+ host : 'krinkle.dev' ,
278+ port : '443' ,
279+ baseUrl : '/w' ,
280+ path : '/w' ,
281+ https : true
282+ } )
283+ expect ( parsedProxyConfig [ 0 ] . proxy ) . to . exist
284+ } )
285+
256286 it ( 'should normalize proxy url' , ( ) => {
257287 var proxy = { '/base/' : 'http://localhost:8000/proxy/test' }
258288 var parsedProxyConfig = m . parseProxyConfig ( proxy , { } )
You can’t perform that action at this time.
0 commit comments