Files
scriptc/tests/fixtures/server/cases/js-dyn-server/driver.mjs
2026-07-22 18:08:04 -05:00

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");