(req, res)
| 19 | } |
| 20 | |
| 21 | function requestHandler(req, res) { |
| 22 | if (req.url === '/close') { |
| 23 | res.end('server closing'); |
| 24 | setTimeout(() => { |
| 25 | process.exit(0); |
| 26 | }, 1000); |
| 27 | } else { |
| 28 | const file = path.resolve(localFolder, req.url); |
| 29 | if (!file.startsWith(localFolder + '/')) { |
| 30 | writeNotFound(res); |
| 31 | return; |
| 32 | } |
| 33 | |
| 34 | fs.readFile(file, function (err, contents) { |
| 35 | if (!err) { |
| 36 | res.end(contents); |
| 37 | } else { |
| 38 | writeNotFound(res); |
| 39 | return; |
| 40 | } |
| 41 | }); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | server = http.createServer(requestHandler).listen(8080); |
nothing calls this directly
no test coverage detected
searching dependent graphs…