index: log remote connecting ip address
This commit is contained in:
parent
72fe25aff9
commit
2448ad1779
14
lib/index.js
14
lib/index.js
@ -109,14 +109,26 @@ InsightAPI.prototype.createLogInfoStream = function() {
|
||||
return stream;
|
||||
};
|
||||
|
||||
InsightAPI.prototype.getRemoteAddress = function(req) {
|
||||
if (req.headers['cf-connecting-ip']) {
|
||||
return req.headers['cf-connecting-ip'];
|
||||
}
|
||||
return req.socket.remoteAddress;
|
||||
};
|
||||
|
||||
InsightAPI.prototype.setupRoutes = function(app) {
|
||||
|
||||
var self = this;
|
||||
|
||||
//Enable rate limiter
|
||||
var limiter = new RateLimiter({node: this.node});
|
||||
app.use(limiter.middleware());
|
||||
|
||||
//Setup logging
|
||||
var logFormat = ':remote-addr ":method :url" :status :res[content-length] :response-time ":user-agent" ';
|
||||
morgan.token('remote-forward-addr', function(req){
|
||||
return self.getRemoteAddress(req);
|
||||
});
|
||||
var logFormat = ':remote-forward-addr ":method :url" :status :res[content-length] :response-time ":user-agent" ';
|
||||
var logStream = this.createLogInfoStream();
|
||||
app.use(morgan(logFormat, {stream: logStream}));
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user