Skip to content

Commit

Permalink
fix: Correctly handle object/json from recordings (#112)
Browse files Browse the repository at this point in the history
Co-authored-by: mauro <[email protected]>
  • Loading branch information
Urogna and mauro authored Aug 26, 2024
1 parent 142231b commit 622318f
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,11 @@ app.all('*', async (req, res) => {
url: req.url,
body: obfuscatedReqBodyForHash,
method: req.method,
headers: headers,
headers: {
...headers,
// since host can be different based on environment, we need to remove it from the hash
host: '',
},
};

const hash = getShaFromData(dataToHash);
Expand Down Expand Up @@ -279,13 +283,14 @@ app.all('*', async (req, res) => {
res.status(status);
if (typeof body === 'object') {
res.setHeader('Content-Type', 'application/json');
res.send(JSON.parse(body));
}
try {
res.setHeader('Content-Type', 'application/json');
res.send(JSON.parse(body));
} catch {
res.send(body);
} else {
try {
res.setHeader('Content-Type', 'application/json');
res.send(JSON.parse(body));
} catch {
res.send(body);
}
}
return;
}
Expand Down

0 comments on commit 622318f

Please sign in to comment.