Add URL logging option
This commit is contained in:
parent
2ea9685bc1
commit
3180839192
|
@ -11,7 +11,8 @@
|
|||
"dependencies": {
|
||||
"cors": "^2.7.1",
|
||||
"express": "^4.13.4",
|
||||
"npm-http-server": "^2.9.1"
|
||||
"npm-http-server": "^2.9.1",
|
||||
"on-finished": "^2.3.0"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
|
20
server.js
20
server.js
|
@ -1,17 +1,33 @@
|
|||
const createRequestHandler = require('npm-http-server').createRequestHandler
|
||||
const express = require('express')
|
||||
const cors = require('cors')
|
||||
const express = require('express')
|
||||
const createRequestHandler = require('npm-http-server').createRequestHandler
|
||||
const onFinished = require('on-finished')
|
||||
|
||||
const registryURL = process.env.npm_package_config_registryURL
|
||||
const bowerBundle = process.env.npm_package_config_bowerBundle
|
||||
const redirectTTL = process.env.npm_package_config_redirectTTL
|
||||
const autoIndex = process.env.npm_package_config_autoIndex
|
||||
const port = process.env.PORT || process.env.npm_package_config_port
|
||||
|
||||
const requestLogging = () =>
|
||||
(req, res, next) => {
|
||||
onFinished(res, () => {
|
||||
if (res.statusCode === 200)
|
||||
console.log(req.url)
|
||||
})
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
const app = express()
|
||||
|
||||
app.disable('x-powered-by')
|
||||
app.use(cors())
|
||||
app.use(express.static('public', { maxAge: 60000 }))
|
||||
|
||||
if (process.env.LOG_URLS)
|
||||
app.use(requestLogging())
|
||||
|
||||
app.use(createRequestHandler({
|
||||
registryURL: registryURL,
|
||||
bowerBundle: bowerBundle,
|
||||
|
|
Loading…
Reference in New Issue