1 | 'use strict'
|
2 |
|
3 | const { extractPageUrl, noop } = require('./tools')
|
4 | const { join } = require('path')
|
5 | const { writeFile } = require('fs')
|
6 | const { getOutput } = require('./output')
|
7 |
|
8 | module.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
|
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 | }
|