mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-23 06:10:02 +08:00
26 lines
637 B
JavaScript
26 lines
637 B
JavaScript
// Two GETs then /quit; print bodies through setEncoding'd responses.
|
|
import { request } from "node:http";
|
|
|
|
const port = Number(process.argv[2]);
|
|
|
|
function get(path) {
|
|
return new Promise((resolve, reject) => {
|
|
const req = request({ host: "127.0.0.1", port, path }, (res) => {
|
|
res.setEncoding("utf8");
|
|
let body = "";
|
|
res.on("data", (c) => (body += c));
|
|
res.on("end", () => {
|
|
console.log(`${path} -> ${res.statusCode} ${body}`);
|
|
resolve();
|
|
});
|
|
});
|
|
req.on("error", reject);
|
|
req.end();
|
|
});
|
|
}
|
|
|
|
await get("/a");
|
|
await get("/b");
|
|
await get("/quit");
|
|
console.log("driver done");
|