diff --git a/index.js b/index.js index 4648bc4..76d715c 100644 --- a/index.js +++ b/index.js @@ -240,6 +240,14 @@ app.post("/v1/messages", (req, res) => { console.log(e); } }); + + res.on("close", function () { + console.log(" > [Client closed]"); + if (stream && typeof stream.destroy === 'function') { + stream.destroy(); + } + }); + stream.on("end", () => { // send ending res.write(createEvent("content_block_stop", { type: "content_block_stop", index: 0 }));