getReadPool().query(sql, function(err, rows, fields) { if (basic.isVoid(rows) || basic.safeGet(rows, ['length'], 0) <= 0) { cb({ errno: -1, errmsg: 'Item ' + r.id + ' not exists', data: err, }); return; } else if (!err && rows) { cb({ errno: 0, errmsg: 'success', data: buildFieldDict(rows[0], ITEM_FIELDS), }); return; } else { cb({ errno: -1, errmsg: 'Get item failed', }); console.log(err); return; } });
exports.bootstrap = function(req, res, next) { try { dbConf = basic.decode( fs.readFileSync(ROOT_PATH + '/conf/db.json', 'utf8'), {} ); if (basic.safeGet(dbConf, ["detail", "aapdb_read_host"])) { res.status(403).send("Database is already init"); return; } //var dbConfPath = ROOT_PATH + "/conf/db.json"; //if (fs.statSync(dbConfPath)) { // res.status(403).send("Database is already init"); // return; //} } catch (e) { if (e.code == "ENOENT") { //do nothing } else { console.log(e); res.status(500).send("Server is currently under some problems."); return; } } if (req.method == 'POST') { if (req.path.indexOf('dbwrite') != -1) { var hdlr = require(ROOT_PATH + '/initialization/dbwrite').initWriteDb; hdlr(req, res); } else if (req.path.indexOf('dbread') != -1) { var hdlr = require(ROOT_PATH + '/initialization/dbread').initReadDb; hdlr(req, res); } else { res.status(404).send('Unknown interface'); } return; } else { var urlpath = req.path; if (urlpath.indexOf('..') != -1) { res.status(404).send('".." in path is forbidden'); return; } res.sendFile(ROOT_PATH + '/static/bootstrap/' + urlpath); } };