From 3b9504161345e0c6ff3aee672151da95547cbf20 Mon Sep 17 00:00:00 2001 From: fenwick67 Date: Sun, 30 Apr 2017 18:32:49 -0500 Subject: [PATCH] add logging by referer header --- index.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index d6be0f7..5e9816d 100644 --- a/index.js +++ b/index.js @@ -6,11 +6,24 @@ var log = console.log; var app = Express(); -app.use(serveStatic('static')); +function logMiddleware(req,res,next){ + log(req.method.toUpperCase() +' '+ req.url); + log( '\t'+ new Date().toISOString() ); + if(req.headers && req.headers.referer){ + log('\tReferer: '+req.headers.referer); + } + return next(null); +} + +app.use(logMiddleware); + +app.use( + serveStatic('static',{ + maxAge:'1d' + }) +); app.get('/api/feed',function(req,res){ - // logging - log(req.url); // get feed url var feedUrl = req.query.url; @@ -40,5 +53,5 @@ app.get('/api/feed',function(req,res){ }); app.listen(process.env.PORT || 8000,function(){ - console.log('listening on '+(process.env.PORT || 8000)); + log('listening on '+(process.env.PORT || 8000)); });