(pathname)
| 341 | } |
| 342 | |
| 343 | function httpJson(pathname) { |
| 344 | return new Promise((resolve, reject) => { |
| 345 | const request = http.get(`${serverUrl}${pathname}`, (response) => { |
| 346 | let body = ""; |
| 347 | response.setEncoding("utf8"); |
| 348 | response.on("data", (chunk) => { |
| 349 | body += chunk; |
| 350 | }); |
| 351 | response.on("end", () => { |
| 352 | if (response.statusCode && response.statusCode >= 400) { |
| 353 | reject( |
| 354 | new Error(`${pathname} returned ${response.statusCode}: ${body}`), |
| 355 | ); |
| 356 | return; |
| 357 | } |
| 358 | try { |
| 359 | resolve(JSON.parse(body)); |
| 360 | } catch (error) { |
| 361 | reject(error); |
| 362 | } |
| 363 | }); |
| 364 | }); |
| 365 | request.on("error", reject); |
| 366 | request.setTimeout(1000, () => { |
| 367 | request.destroy(new Error("health request timed out")); |
| 368 | }); |
| 369 | }); |
| 370 | } |
| 371 | |
| 372 | function pngSize(filePath) { |
| 373 | const buffer = fs.readFileSync(filePath); |
no test coverage detected