-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.js
53 lines (46 loc) · 2.28 KB
/
logger.js
1
module.exports = function logger(options) { var stream = options.stream || process.stdout; return function logger(req, res, next) { if (/^\/despatch(?:\w*)/i.test(req.url)) { var ua = req.headers['user-agent'], browser = { opera: /opera/i.test(ua), msie: (/msie/i.test(ua) && !/opera/i.test(ua)), msie6: (/msie 6/i.test(ua) && !/opera/i.test(ua)), msie7: (/msie 7/i.test(ua) && !/opera/i.test(ua)), msie8: (/msie 8/i.test(ua) && !/opera/i.test(ua)), msie9: (/msie 9/i.test(ua) && !/opera/i.test(ua)), mozilla: /firefox/i.test(ua), chrome: /chrome/i.test(ua), safari: (!(/chrome/i.test(ua)) && /webkit|safari|khtml/i.test(ua)), webkit: /webkit/i.test(ua), iphone: /iphone/i.test(ua), ipod: /ipod/i.test(ua), iphone4: /iphone.*OS 4/i.test(ua), ipod4: /ipod.*OS 4/i.test(ua), ipad: /ipad/i.test(ua), android: /android/i.test(ua), bada: /bada/i.test(ua), mobile: /iphone|ipod|ipad|opera mini|opera mobi|iemobile|android/i.test(ua), msie_mobile: /iemobile/i.test(ua), safari_mobile: /iphone|ipod|ipad/i.test(ua), opera_mobile: /opera mini|opera mobi/i.test(ua), opera_mini: /opera mini/i.test(ua), mac: /mac/i.test(ua), version: (ua.match( /.+(?:me|ox|on|rv|it|era|ie)[\/: ]([\d.]+)/ ) || [0,'0'])[1] }, Ua=[],b=browser,k;for(var k in b){b[k] && Ua.push('version'==k?b[k]:k)};Ua=Ua.join('|'); var urlRequest = require("url").parse(req.url, true); var query = urlRequest.query, line = JSON.stringify(query) + ' - ' + Ua; console.log(line); stream.write(line + '\n'); res.setHeader("Content-Type", "image/gif"); res.setHeader("Content-Lenght", "0"); res.setHeader("Access-Control-Allow-Origin", "*"); res.end(); } else { next(); } };};