| 485 | } |
| 486 | |
| 487 | function postJson(url, body) { |
| 488 | const payload = JSON.stringify(body); |
| 489 | return new Promise((resolve, reject) => { |
| 490 | const req = http.request( |
| 491 | url, |
| 492 | { |
| 493 | method: "POST", |
| 494 | headers: { |
| 495 | "content-type": "application/json", |
| 496 | "content-length": Buffer.byteLength(payload), |
| 497 | }, |
| 498 | }, |
| 499 | (response) => { |
| 500 | response.setEncoding("utf8"); |
| 501 | let buf = ""; |
| 502 | response.on("data", (chunk) => { |
| 503 | buf += chunk; |
| 504 | }); |
| 505 | response.on("end", () => { |
| 506 | resolve({ body: buf, headers: response.headers, statusCode: response.statusCode }); |
| 507 | }); |
| 508 | }, |
| 509 | ); |
| 510 | req.once("error", reject); |
| 511 | req.write(payload); |
| 512 | req.end(); |
| 513 | }); |
| 514 | } |
| 515 | |
| 516 | function stopProcess(child) { |
| 517 | return new Promise((resolve, reject) => { |