Remove logging of package requests
This commit is contained in:
parent
a3197e803a
commit
9381525d05
|
@ -16,7 +16,6 @@
|
||||||
"express-unpkg": "^1.1.1",
|
"express-unpkg": "^1.1.1",
|
||||||
"http-client": "^4.3.1",
|
"http-client": "^4.3.1",
|
||||||
"morgan": "^1.8.1",
|
"morgan": "^1.8.1",
|
||||||
"on-finished": "^2.3.0",
|
|
||||||
"pretty-bytes": "^3",
|
"pretty-bytes": "^3",
|
||||||
"prop-types": "^15.5.8",
|
"prop-types": "^15.5.8",
|
||||||
"react": "^15.5.4",
|
"react": "^15.5.4",
|
||||||
|
|
|
@ -5,7 +5,6 @@ const cors = require('cors')
|
||||||
const morgan = require('morgan')
|
const morgan = require('morgan')
|
||||||
const unpkg = require('express-unpkg')
|
const unpkg = require('express-unpkg')
|
||||||
const { fetchStats } = require('./cloudflare')
|
const { fetchStats } = require('./cloudflare')
|
||||||
const { logPackageRequests } = require('./logging')
|
|
||||||
|
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
@ -52,9 +51,6 @@ const createServer = (config) => {
|
||||||
maxAge: config.maxAge
|
maxAge: config.maxAge
|
||||||
}))
|
}))
|
||||||
|
|
||||||
if (config.redisURL)
|
|
||||||
app.use(logPackageRequests(config.redisURL))
|
|
||||||
|
|
||||||
app.use(unpkg.createRequestHandler(config))
|
app.use(unpkg.createRequestHandler(config))
|
||||||
|
|
||||||
const server = http.createServer(app)
|
const server = http.createServer(app)
|
||||||
|
|
|
@ -1,31 +0,0 @@
|
||||||
const redis = require('redis')
|
|
||||||
const onFinished = require('on-finished')
|
|
||||||
|
|
||||||
const URLFormat = /^\/((?:@[^\/@]+\/)?[^\/@]+)(?:@([^\/]+))?(\/.*)?$/
|
|
||||||
|
|
||||||
const logPackageRequests = (redisURL) => {
|
|
||||||
const redisClient = redis.createClient(redisURL)
|
|
||||||
|
|
||||||
return (req, res, next) => {
|
|
||||||
onFinished(res, () => {
|
|
||||||
const path = req.path
|
|
||||||
|
|
||||||
if (res.statusCode === 200 && path.charAt(path.length - 1) !== '/') {
|
|
||||||
//redisClient.zincrby([ 'request-paths', 1, path ])
|
|
||||||
|
|
||||||
const match = URLFormat.exec(path)
|
|
||||||
|
|
||||||
if (match) {
|
|
||||||
const packageName = match[1]
|
|
||||||
redisClient.zincrby([ 'package-requests', 1, packageName ])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
next()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
logPackageRequests
|
|
||||||
}
|
|
Loading…
Reference in New Issue