Files
weiguang-jewelry-ledger/新账系统/server/middleware/body.js
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

16 lines
454 B
JavaScript
Raw Normal View History

'use strict';
const { fail } = require('../../ledger');
// 保持原样(含按块拼接字符串的已知问题),修正留到下一阶段。
async function readBody(req) {
let raw = '';
for await (const chunk of req) {
raw += chunk;
if (Buffer.byteLength(raw) > 300000) fail('内容过大', 413);
}
try {
return JSON.parse(raw || '{}');
} catch {
fail('请求内容不是有效JSON');
}
}
module.exports = { readBody };