File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -108,10 +108,10 @@ export async function buildApp(
108108 operation ,
109109 ) ;
110110
111- const patchedHeaders = Object . assign (
112- req . headers ,
113- { host : new URL ( targetUrl ) . hostname }
114- ) ;
111+ const patchedHeaders = {
112+ ... req . headers ,
113+ host : new URL ( targetUrl ) . hostname ,
114+ } ;
115115
116116 const options : rp . Options = {
117117 url : targetUrl . replace ( / \/ $ / , '' ) + req . params [ 0 ] ,
@@ -164,12 +164,14 @@ export async function buildApp(
164164 // unmodified server response
165165 res . status ( statusCode ) . send ( serverResponse . body ) ;
166166 } else {
167+ // Replace response payload with parsed payload due to practicality
168+ serverResponse . body = parsedResponseBody ;
167169 // when not silent, render validation results on error
168170 res . status ( 500 ) . json ( {
169171 error : {
170172 message : 'openapi-cop Proxy validation failed' ,
171173 request : oasRequest ,
172- response : Object . assign ( serverResponse , { body : parsedResponseBody } ) ,
174+ response : serverResponse ,
173175 validationResults
174176 }
175177 } ) ;
Original file line number Diff line number Diff line change @@ -66,7 +66,7 @@ const defaultPorts: { [key: string]: number } = {
6666}
6767const targetPort = ( targetUrl . port !== '' ) ? Number ( targetUrl . port ) : defaultPorts [ targetUrl . protocol ] ;
6868
69- if ( ( targetUrl . hostname === 'localhost' || targetUrl . hostname === '0.0.0.0' ) && ( Number ( program . port ) === targetPort ) ) {
69+ if ( ( targetUrl . hostname === 'localhost' || targetUrl . hostname === '0.0.0.0' ) && Number ( program . port ) === targetPort ) {
7070 console . error ( 'Cannot proxy to the same local port: ' + program . port ) ;
7171 process . exit ( ) ;
7272}
You can’t perform that action at this time.
0 commit comments