Verified Commit 1f266643 authored by Aral Balkan's avatar Aral Balkan
Browse files

Progress on logging referrers

Currently coming up as ::1 on testing, even via ngrok
parent 2e1668e4
......@@ -221,7 +221,8 @@ class Site {
// Create an express server to serve the path using Morgan for logging.
const app = express()
app.use(helmet()) // Express.js security with HTTP headers.
app.set('trust-proxy', true )
// app.use(helmet()) // Express.js security with HTTP headers.
// Statistics middleware (captures anonymous, ephemeral statistics).
app.use(stats.middleware)
......
......@@ -6,6 +6,7 @@
const fs = require('fs')
const crypto = require('crypto')
const requestIp = require('request-ip')
class Stats {
......@@ -61,11 +62,15 @@ class Stats {
const referrer = request.get('Referrer')
const clientIp = requestIp.getClientIp(request)
console.log('ip', clientIp)
if (referrer !== undefined) {
this.referrers[referrer] === undefined ? this.referrers[referrer] = 1 : this.referrers[referrer]++
}
response.on('finish', () => {
if (response.statusCode === 404) {
this.missing.add(request.path)
}
......
......@@ -3152,6 +3152,11 @@
"is-url": "^1.2.2"
}
},
"is_js": {
"version": "0.9.0",
"resolved": "https://registry.npmjs.org/is_js/-/is_js-0.9.0.tgz",
"integrity": "sha1-CrlFQFArp6+iTIVqqYVWFmnpxS0="
},
"isarray": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
......@@ -4502,6 +4507,14 @@
"resolved": "https://registry.npmjs.org/repeat-string/-/repeat-string-1.6.1.tgz",
"integrity": "sha1-jcrkcOHIirwtYA//Sndihtp15jc="
},
"request-ip": {
"version": "2.1.3",
"resolved": "https://registry.npmjs.org/request-ip/-/request-ip-2.1.3.tgz",
"integrity": "sha512-J3qdE/IhVM3BXkwMIVO4yFrvhJlU3H7JH16+6yHucadT4fePnR8dyh+vEs6FIx0S2x5TCt2ptiPfHcn0sqhbYQ==",
"requires": {
"is_js": "^0.9.0"
}
},
"require-directory": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment