mirror of
https://git.sr.ht/~cadence/bibliogram
synced 2024-11-22 08:07:30 +00:00
Don't crash if log line isn't understood
This commit is contained in:
parent
5c5339e34e
commit
d98618a934
@ -89,6 +89,11 @@ const regex = /^([^ ]+) - - \[([^\]]+)\] "([A-Z]+) ([^"]+) HTTP\/(?:1.0|1.1|2.0)
|
||||
|
||||
function parseLine(line) {
|
||||
const result = line.match(regex)
|
||||
if (!result) {
|
||||
console.log("Line didn't match regular expression:")
|
||||
console.log(line)
|
||||
return null
|
||||
} else {
|
||||
return {
|
||||
ip: result[1],
|
||||
date: result[2],
|
||||
@ -99,6 +104,7 @@ function parseLine(line) {
|
||||
userAgent: result[7]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const additionalStatic = ["/android-chrome-512x512.png", "/safari-pinned-tab.svg", "/robots.txt", "/site.webmanifest", "/apple-touch-icon.png", "/favicon-32x32.png", "/favicon-16x16.png", "/favicon.ico", "/android-chrome-192x192.png"]
|
||||
|
||||
@ -124,6 +130,7 @@ let dateCollection = null
|
||||
|
||||
reader.on("line", line => {
|
||||
const parsed = parseLine(line)
|
||||
if (!parsed) return
|
||||
const dateObject = new Date(parsed.date.replace(":", " "))
|
||||
|
||||
//console.log(parsed)
|
||||
|
Loading…
Reference in New Issue
Block a user