Introduce processor
This commit is contained in:
parent
68ce6d5748
commit
90f8fe7e53
582 changed files with 246 additions and 188 deletions
21
src/server/log-request.ts
Normal file
21
src/server/log-request.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
import * as crypto from 'crypto';
|
||||
import * as express from 'express';
|
||||
import * as proxyAddr from 'proxy-addr';
|
||||
import Xev from 'xev';
|
||||
|
||||
const ev = new Xev();
|
||||
|
||||
export default function(req: express.Request) {
|
||||
const ip = proxyAddr(req, () => true);
|
||||
|
||||
const md5 = crypto.createHash('md5');
|
||||
md5.update(ip);
|
||||
const hashedIp = md5.digest('hex').substr(0, 3);
|
||||
|
||||
ev.emit('request', {
|
||||
ip: hashedIp,
|
||||
method: req.method,
|
||||
hostname: req.hostname,
|
||||
path: req.originalUrl
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue