Verified Commit 531ede9e authored by Sebastiaan Deckers's avatar Sebastiaan Deckers 馃悜

fix: do not log spammy 404 error traces

parent e7f71763
......@@ -5,7 +5,13 @@ const mkdirp = require('mkdirp')
const prefix = '/.well-known/acme-challenge/'
module.exports = async (fastify, options) => {
const server = require('fastify')({ logger: true })
const logger = 'logger' in options ? options.logger : true
const server = require('fastify')({ logger })
server.setErrorHandler(async (error, request, reply) => {
if (error.statusCode !== 404) {
throw error
}
})
const root = join(options.webroot, prefix)
await promisify(mkdirp)(root)
server.register(require('../routes/get'))
......
......@@ -6,8 +6,11 @@ module.exports = async (configuration) => {
throw new Error('Missing server configuration')
}
const logger = 'logger' in configuration
? configuration.logger : true
const fastify = require('fastify')({
logger: true,
logger,
http2: true,
https: {
allowHTTP1: true,
......
const test = require('blue-tape')
const configuration = require('../core.conf.example.js')
const fetch = require('node-fetch')
const logs = []
const log = (type) => (message) => {
// const { req, res, err } = message
// console.log(type, { req: !!req, res: !!res, err: !!err })
logs.push([type, message])
}
const logger = {
info: log('info'),
error: log('error'),
debug: log('debug'),
fatal: log('fatal'),
warn: log('warn'),
trace: log('trace'),
child: () => logger
}
require('./helpers/setup')({
...configuration,
acme: { ...configuration.acme, logger }
})
test('Avoid log spam from static 404 errors by bots', async (t) => {
while (logs.length > 0) logs.pop()
const origin = `http://localhost:${configuration.acme.port}`
const target = '/wp-content/plugins/portable-phpmyadmin/wp-pma-mod/index.php'
const url = `${origin}${target}`
const response = await fetch(url)
t.is(response.status, 404)
const text = await response.text()
t.is(text, '{"statusCode":404,"error":"Not Found","message":"Not Found"}')
t.true(logs.length > 0)
t.ok(logs.every(([type, { err }]) => err === undefined))
})
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