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

16 lines
719 B
JavaScript

'use strict';
const { fail } = require('../core/ledger');
const send = (res, status, data, contentType = 'application/json; charset=utf-8') => {
if (contentType.startsWith('text/html') && res.remainingBusinessTime) {
const remaining = Math.max(0, res.remainingBusinessTime());
data = data
.toString()
.replace('</body>', `<script src="/business-hours-lock.js" data-remaining="${remaining}"></script></body>`);
}
res.writeHead(status, { 'Content-Type': contentType });
res.end(contentType.startsWith('application/json') ? JSON.stringify(data) : data);
};
const notFound = () => fail('地址不存在', 404);
const HTML = 'text/html; charset=utf-8';
module.exports = { send, notFound, HTML };