mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Reduced logging output
This commit is contained in:
parent
9ae7930141
commit
d6edfa15e1
2 changed files with 72 additions and 13 deletions
18
server.js
18
server.js
|
@ -65,20 +65,11 @@ try {
|
|||
var newMessages = "";
|
||||
|
||||
app.set('view engine', 'ejs');
|
||||
app.use(function(req, res, next) {
|
||||
var ip = req.headers['cf-connecting-ip'] || req.connection.remoteAddress;
|
||||
if (req.headers['cf-connecting-ip']) {
|
||||
next();
|
||||
} else {
|
||||
res.status(404);
|
||||
res.end();
|
||||
logger.Log("[BLOCK]: " + req.connection.remoteAddress + " blocked, " + req.url, logger.GetColor("redbg"));
|
||||
}
|
||||
});
|
||||
app.use(function(req, res, next) {
|
||||
res.on('finish', function() {
|
||||
if (res.statusCode != 404 && req.connection.remoteAddress != "::1")
|
||||
Log(req);
|
||||
if (res.statusCode != 404 && req.connection.remoteAddress != "::1"){
|
||||
// Log(req);
|
||||
}
|
||||
else
|
||||
Log(req, true);
|
||||
});
|
||||
|
@ -124,7 +115,6 @@ app.get('/static', function(req, res) {
|
|||
});
|
||||
|
||||
app.post('/postquestions', function(req, res) {
|
||||
//res.redirect('back');
|
||||
var log = "Questions posted! ";
|
||||
if (req.body.data_field == undefined) {
|
||||
res.render('submitted', {
|
||||
|
@ -231,10 +221,12 @@ app.get('/sanityCheck', function(req, res) {
|
|||
|
||||
app.get('/scriptgit', function(req, res) {
|
||||
res.redirect("https://gitlab.com/YourFriendlyNeighborhoodDealer/moodle-test-userscript");
|
||||
res.end();
|
||||
});
|
||||
|
||||
app.get('/servergit', function(req, res) {
|
||||
res.redirect("https://gitlab.com/YourFriendlyNeighborhoodDealer/question-node-server");
|
||||
res.end();
|
||||
});
|
||||
|
||||
app.get('*', function(req, res) {
|
||||
|
|
67
utils.js
Normal file
67
utils.js
Normal file
|
@ -0,0 +1,67 @@
|
|||
module.exports = {
|
||||
ReadFile: ReadFile,
|
||||
WriteFile: WriteFile,
|
||||
writeFileAsync: WriteFileAsync,
|
||||
AppendToFile: AppendToFile,
|
||||
Beep: Beep,
|
||||
WriteBackup: WriteBackup
|
||||
};
|
||||
|
||||
var fs = require('fs');
|
||||
|
||||
var logger = require('./logger.js');
|
||||
|
||||
const recievedFile = "stats/recieved";
|
||||
const publicFile = "public/data/public";
|
||||
const staticFile = "public/data/static";
|
||||
const manFile = "public/man.html";
|
||||
const logFile = "stats/logs";
|
||||
|
||||
function ReadFile(name) {
|
||||
return fs.readFileSync(name, "utf8");
|
||||
}
|
||||
|
||||
function WriteFile(content, path) {
|
||||
fs.writeFileSync(path, content);
|
||||
}
|
||||
|
||||
function WriteFileAsync(content, path) {
|
||||
fs.writeFile(path, content, function(err) {
|
||||
if (err) {
|
||||
logger.Log("[ERR ]: Error writing file: " + path + " (sync)", logger.GetColor("redbg"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function AppendToFile(data, file) {
|
||||
fs.appendFile(file, "\n" + data, function(err) {
|
||||
if (err)
|
||||
logger.Log("[ERR ]: Error writing log file: " + path + " (sync)", logger.GetColor("redbg"));
|
||||
});
|
||||
}
|
||||
|
||||
function Beep() {
|
||||
try {
|
||||
process.stdout.write('\x07');
|
||||
} catch (e) {
|
||||
console.log("error beepin");
|
||||
}
|
||||
}
|
||||
|
||||
function WriteBackup() {
|
||||
try {
|
||||
WriteFileAsync(ReadFile(recievedFile), 'public/backs/recieved_' + new Date().toString());
|
||||
//logger.Log('[SAVE]: New questions backup wrote');
|
||||
|
||||
} catch (e) {
|
||||
logger.Log("[ERR ]: Error backing up recieved file!", logger.GetColor("redbg"));
|
||||
console.log(e);
|
||||
}
|
||||
try {
|
||||
WriteFileAsync(ReadFile(publicFile), 'public/backs/public_' + new Date().toString());
|
||||
//logger.Log('[SAVE]: Public questions backup wrote');
|
||||
} catch (e) {
|
||||
logger.Log("[ERR ]: Error backing up public file!", logger.GetColor("redbg"), true);
|
||||
console.log(e);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue