UNPKG

890 BJavaScriptView Raw
1'use strict'
2
3const { extractPageUrl, noop } = require('./tools')
4const { join } = require('path')
5const { writeFile } = require('fs')
6const { getOutput } = require('./output')
7
8module.exports = job => {
9 const unhandled = join(job.reportDir, 'unhandled.txt')
10 let outputUnhandled = true
11 return [{
12 custom: ({ headers, method, url }) => {
13 if (method === 'GET' && url.match(/favicon\.ico$|-preload\.js$|-dbg(\.[^.]+)*\.js$|i18n_\w+\.properties$/)) {
14 return 404 // expected
15 }
16 let status
17 if (method === 'GET') {
18 status = 404
19 } else {
20 status = 500
21 }
22 if (outputUnhandled) {
23 getOutput(job).unhandled()
24 outputUnhandled = false
25 }
26 writeFile(unhandled, `${extractPageUrl(headers) || headers.referer} ${status} ${method} ${url}\n`, {
27 flag: 'a'
28 }, noop)
29 return status
30 }
31 }]
32}