Fix: res.setBody fails for Object in Developer-mode

vm2 returns a recursive Proxy for accessing the return value which
cannot be serialized for IPC using `structuredClone`.

Co-authored-by: ramki-bruno <ramki@usebruno.com>
This commit is contained in:
sanish-bruno
2025-02-06 17:38:14 +05:30
committed by Anoop M D
parent 9ef2699372
commit 592679538b
2 changed files with 5 additions and 2 deletions

View File

@@ -35,6 +35,7 @@ if (!SERVER_RENDERED) {
'res.getHeader(name)',
'res.getHeaders()',
'res.getBody()',
'res.setBody(data)',
'res.getResponseTime()',
'req',
'req.url',

View File

@@ -1,4 +1,5 @@
const { get } = require('@usebruno/query');
const _ = require('lodash');
class BrunoResponse {
constructor(res) {
@@ -46,8 +47,9 @@ class BrunoResponse {
return;
}
this.body = data;
this.res.data = data;
const clonedData = _.cloneDeep(data);
this.res.data = clonedData;
this.body = clonedData;
}
}