Skip to content

Commit dce82ca

Browse files
committed
feat: 优化内存
1 parent d9e427c commit dce82ca

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

server/proxy.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,18 @@ async function serverProxy({
6363
const apiCount = tool.file.fileStore(global.config._store).updateApiCount()
6464
const apiId = tool.hex.string10to62(apiCount)
6565
req.apiId = apiId
66-
const cloneDeep = require(`lodash.clonedeep`)
67-
const newReq = cloneDeep(req) // 如果不 cloneDeep, 那么 req.body 到 send 回调中会被改变
66+
67+
// 只拷贝必要的字段,避免深拷贝整个req对象
68+
const newReq = {
69+
method: req.method,
70+
url: req.url,
71+
originalUrl: req.originalUrl,
72+
headers: {...req.headers}, // 浅拷贝headers
73+
body: req.body ? JSON.parse(JSON.stringify(req.body)) : undefined, // 只深拷贝body
74+
query: {...req.query}, // 浅拷贝query
75+
params: {...req.params}, // 浅拷贝params
76+
apiId: apiId
77+
}
6878
const oldSend = res.send
6979
res.send = (data = ``) => {
7080
let buffer = undefined

0 commit comments

Comments
 (0)