Skip to content

Commit 53d30b0

Browse files
committed
Apply minor code style changes
1 parent 51d226a commit 53d30b0

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

src/app.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff 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
});

src/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const defaultPorts: { [key: string]: number } = {
6666
}
6767
const 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
}

0 commit comments

Comments
 (0)