mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Decaf cleanup
This commit is contained in:
parent
0e3389305a
commit
7274217d79
1 changed files with 7 additions and 22 deletions
|
@ -1,10 +1,3 @@
|
||||||
/*
|
|
||||||
* decaffeinate suggestions:
|
|
||||||
* DS102: Remove unnecessary code created because of implicit returns
|
|
||||||
* DS103: Rewrite code to no longer use __guard__
|
|
||||||
* DS207: Consider shorter variations of null checks
|
|
||||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
||||||
*/
|
|
||||||
const yn = require('yn')
|
const yn = require('yn')
|
||||||
|
|
||||||
const STACKDRIVER_LOGGING = yn(process.env.STACKDRIVER_LOGGING)
|
const STACKDRIVER_LOGGING = yn(process.env.STACKDRIVER_LOGGING)
|
||||||
|
@ -15,14 +8,13 @@ module.exports.monitor = logger =>
|
||||||
const startTime = process.hrtime()
|
const startTime = process.hrtime()
|
||||||
const { end } = res
|
const { end } = res
|
||||||
res.end = function() {
|
res.end = function() {
|
||||||
let info
|
|
||||||
end.apply(this, arguments)
|
end.apply(this, arguments)
|
||||||
const responseTime = process.hrtime(startTime)
|
const responseTime = process.hrtime(startTime)
|
||||||
const responseTimeMs = Math.round(
|
const responseTimeMs = Math.round(
|
||||||
responseTime[0] * 1000 + responseTime[1] / 1000000
|
responseTime[0] * 1000 + responseTime[1] / 1000000
|
||||||
)
|
)
|
||||||
const requestSize = parseInt(req.headers['content-length'], 10)
|
const requestSize = parseInt(req.headers['content-length'], 10)
|
||||||
if ((req.route != null ? req.route.path : undefined) != null) {
|
if (req.route && req.route.path != null) {
|
||||||
const routePath = req.route.path
|
const routePath = req.route.path
|
||||||
.toString()
|
.toString()
|
||||||
.replace(/\//g, '_')
|
.replace(/\//g, '_')
|
||||||
|
@ -43,13 +35,12 @@ module.exports.monitor = logger =>
|
||||||
}
|
}
|
||||||
const remoteIp =
|
const remoteIp =
|
||||||
req.ip ||
|
req.ip ||
|
||||||
__guard__(
|
(req.socket && req.socket.socket && req.socket.socket.remoteAddress) ||
|
||||||
req.socket != null ? req.socket.socket : undefined,
|
(req.socket && req.socket.remoteAddress)
|
||||||
x => x.remoteAddress
|
|
||||||
) ||
|
|
||||||
(req.socket != null ? req.socket.remoteAddress : undefined)
|
|
||||||
const reqUrl = req.originalUrl || req.url
|
const reqUrl = req.originalUrl || req.url
|
||||||
const referrer = req.headers.referer || req.headers.referrer
|
const referrer = req.headers.referer || req.headers.referrer
|
||||||
|
|
||||||
|
let info
|
||||||
if (STACKDRIVER_LOGGING) {
|
if (STACKDRIVER_LOGGING) {
|
||||||
info = {
|
info = {
|
||||||
httpRequest: {
|
httpRequest: {
|
||||||
|
@ -85,13 +76,7 @@ module.exports.monitor = logger =>
|
||||||
'response-time': responseTimeMs
|
'response-time': responseTimeMs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return logger.info(info, '%s %s', req.method, reqUrl)
|
logger.info(info, '%s %s', req.method, reqUrl)
|
||||||
}
|
}
|
||||||
return next()
|
next()
|
||||||
}
|
}
|
||||||
|
|
||||||
function __guard__(value, transform) {
|
|
||||||
return typeof value !== 'undefined' && value !== null
|
|
||||||
? transform(value)
|
|
||||||
: undefined
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue