Handling Requests multimessage

This commit is contained in:
Joe
2019-01-07 07:51:40 -06:00
parent bdf24867f8
commit e29b4b9e86
3 changed files with 40 additions and 25 deletions

View File

@@ -27,23 +27,27 @@ const server = micro(async (req, res) => {
const js = await json(req);
try {
inputLine = JSON.parse(js);
allInputLines = JSON.parse(js);
send(res, 200, "OK");
} catch (ex) {
logger.log("error", "Input not in JSON format:" + line);
logger.log("error", "Input not in JSON format:" + js);
send(res, 401, "Input not in JSON Format");
}
let isWhiteListed = ruleEngine.processData(inputLine);
let miniInput = jsonminify(JSON.stringify(inputLine));
let now = Date();
if (isWhiteListed) {
logger.log("debug", "Not Whitelisted: " + miniInput);
fs.appendFileSync("./log/skipped.log", miniInput + "\n");
} else {
logger.log("info", "Not Whitelisted: " + miniInput);
fs.appendFileSync("./log/issues.log", miniInput + "\n");
for(i=0;i<allInputLines.length;i++){
let theInputLine=allInputLines[i];
let isWhiteListed = ruleEngine.processData(theInputLine);
let miniInput = jsonminify(JSON.stringify(theInputLine));
let now = Date();
if (isWhiteListed) {
logger.log("debug", "Not Whitelisted: " + miniInput);
fs.appendFileSync("./log/skipped.log", miniInput + "\n");
} else {
logger.log("info", "Not Whitelisted: " + miniInput);
fs.appendFileSync("./log/issues.log", miniInput + "\n");
}
}
send(res, 200, "OK");
});
server.listen(2222);