brenden / node-webshot

Easy website screenshots in Node.js
2.12k stars 285 forks source link

Console running multiple times #163

Open cookie-ag opened 8 years ago

cookie-ag commented 8 years ago

Here is my code

var webshot = require('webshot');
var fs = require('fs');
var domain = require('../config').domain;

exports.error404 = function(req, res, next) {
    var err = new Error('Not found');
    err.status = 404;

    if (!req.user) {

webshot(domain + req.path,RID + '_Error.png',function(err) {
  if(err){
    console.log(err);
  }
});

        req.flash('ErrorMSG', '' + req.path + ' is not allowed, redirecting to Login.');
        console.log("Logging HTTP Error : " + err.status + " - " + err.message + " - " + req.path + " - From " + req.connection.remoteAddress + " - Using " + req.headers['user-agent'] + " - By Unauthenticated" + " - Request ID : " + RID);
    }
    if (req.user) {
        req.flash('ErrorMSGLoggedin', '' + req.path + ' is not allowed, redirecting to tasks.');
        console.log("Logging HTTP Error : " + err.status + " - " + err.message + " - " + req.path + " - From " + req.connection.remoteAddress + " - Using " + req.headers['user-agent'] + " - By " + req.session.email + " - Request ID : " + RID);
    }
    res.redirect('/login');
};

Whenever i GET an undefined path the same goes into loop filling my console screen with multiple queries. It was all ok before. Any ideas?

screen shot 2016-08-28 at 6 49 53 pm