diff --git a/lib/userver.ts b/lib/userver.ts index 38c9b5a8..66fa4041 100644 --- a/lib/userver.ts +++ b/lib/userver.ts @@ -275,6 +275,10 @@ class ResponseWrapper { this.res.end(data); } + public onData(fn) { + this.res.onData(fn); + } + public onAborted(fn) { this.res.onAborted(fn); } diff --git a/test/server.js b/test/server.js index 3aff7c0e..d7d64428 100644 --- a/test/server.js +++ b/test/server.js @@ -3552,6 +3552,31 @@ describe("server", () => { } ); }); + + it("should work with CORS enabled", done => { + engine = listen( + { cors: { origin: true, headers: ["my-header"], credentials: true } }, + port => { + const client = new ClientSocket(`ws://localhost:${port}`, { + transports: ["polling"] + }); + engine.on("connection", socket => { + socket.on("message", msg => { + expect(msg).to.be("hey"); + socket.send("holà"); + }); + }); + client.on("open", () => { + client.send("hey"); + }); + client.on("message", msg => { + expect(msg).to.be("holà"); + client.close(); + done(); + }); + } + ); + }); }); describe("wsEngine option", () => {