webio-node/route/ResTool.js

38 lines
1021 B
JavaScript

const errList = require('../includes/errorManager');
function send(req, res) {
if ('db' in res && typeof res.db == 'object' && 'close' in res.db && typeof res.db.close == 'function') res.db.close();
if ('db' in res && typeof res.db == 'object' && 'release' in res.db && typeof res.db.release == 'function') res.db.release();
let lngs = req.headers['accept-language'] || '';
lngs = lngs.split(',');
let lng = null;
if (lngs.length > 0) {
lng = lngs[0].substring(0, 2);
}
let json = {};
if (!('api_res' in res)) {
json = {
errorCode: 'ERR9999',
message: 'api not found',
status: 0
};
} else if (typeof res.api_res != 'object') {
json = {
errorCode: res.api_res,
message: errList(res.api_res, lng),
status: 0
};
} else {
json = {
data: res.api_res,
status: 1
};
}
res.send(json);
}
module.exports = { send: send };