本文介绍了避免在Express.js中记录图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在节点中使用Express.JS,并且在记录器生成的日志文件中看到了这一点.我想避免记录图像,如何设置要保存在日志文件中的请求类型?
I'm using Express.JS in node, and i saw that in the log file generate by the logger. I would like to avoid the logging of the image, how could I set the type of requests I want to save in the log file?
谢谢!
推荐答案
这应该可以解决问题
var express = require("express");
var logger = express.logger();
var app = express.createServer();
var conditionalLogger = function (req, res, next) {
if (!(/\.(png|jpg|gif|jpeg)$/i).test(req.path)) {
logger(req, res, next);
} else {
next();
}
}
app.use(conditionalLogger);
app.use(express.static("./public"));
app.listen(3456);
这篇关于避免在Express.js中记录图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!