import http from "node:http";
http.createServer((req, res) => {
let body = "";
req.on("data", (c) => (body += c));
req.on("end", () => {
// 本文 {"jsonrpc":"2.0","method":"getUser","params":{"id":123},"id":1} が来たら
const msg = JSON.parse(body);
if (msg.method === "getUser") {
const result = getUser(msg.params.id); // ← ここで呼ばれる
res.end(JSON.stringify({ jsonrpc: "2.0", result, id: msg.id }));
}
});
}).listen(3001);