|
|
@ -377,6 +377,11 @@ app.runOnStartup = function() { |
|
|
|
setInterval(utils.logMemoryUsage, 5000); |
|
|
|
}; |
|
|
|
|
|
|
|
app.use(function(req, res, next) { |
|
|
|
req.start = Date.now(); |
|
|
|
next(); |
|
|
|
}); |
|
|
|
|
|
|
|
app.use(function(req, res, next) { |
|
|
|
// make session available in templates
|
|
|
|
res.locals.session = req.session; |
|
|
@ -394,15 +399,6 @@ app.use(function(req, res, next) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (global.influxdb) { |
|
|
|
var points = []; |
|
|
|
points.push({measurement:`express.request`, app:("btc-rpc-explorer." + global.config.coin), fields:{count:1, host:req.hostname, path:req.path, userAgent:userAgent}}); |
|
|
|
|
|
|
|
global.influxdb.writePoints(points).catch(err => { |
|
|
|
console.error(`Error saving data to InfluxDB: ${err.stack}`); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
res.locals.config = global.config; |
|
|
|
res.locals.coinConfig = global.coinConfig; |
|
|
|
|
|
|
@ -496,6 +492,27 @@ app.use(function(req, res, next) { |
|
|
|
next(); |
|
|
|
}); |
|
|
|
|
|
|
|
app.use(function(req, res, next) { |
|
|
|
var time = Date.now() - req.start; |
|
|
|
|
|
|
|
console.log("time: " + time); |
|
|
|
|
|
|
|
if (global.influxdb) { |
|
|
|
var points = []; |
|
|
|
points.push({ |
|
|
|
measurement:`express.request`, |
|
|
|
tags:{app:("btc-rpc-explorer." + global.config.coin), host:req.hostname, path:req.path, userAgent:req.headers['user-agent']}, |
|
|
|
fields:{count:1, time:time} |
|
|
|
}); |
|
|
|
|
|
|
|
global.influxdb.writePoints(points).catch(err => { |
|
|
|
console.error(`Error saving data to InfluxDB: ${err.stack}`); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
next(); |
|
|
|
}); |
|
|
|
|
|
|
|
app.use(csurf(), (req, res, next) => { |
|
|
|
res.locals.csrfToken = req.csrfToken(); |
|
|
|
next(); |
|
|
|