From ce53d6bdb1a61de0f81dad39a978dec92e286071 Mon Sep 17 00:00:00 2001 From: Max Romanov Date: Wed, 8 Apr 2020 14:44:53 +0300 Subject: Node.js: fixing Server.listen() method. This is required for Express framework compatibility. This closes #418 issue on GitHub. --- src/nodejs/unit-http/http_server.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/nodejs') diff --git a/src/nodejs/unit-http/http_server.js b/src/nodejs/unit-http/http_server.js index 2f324329..d378e410 100644 --- a/src/nodejs/unit-http/http_server.js +++ b/src/nodejs/unit-http/http_server.js @@ -451,8 +451,18 @@ Server.prototype.setTimeout = function setTimeout(msecs, callback) { return this; }; -Server.prototype.listen = function () { +Server.prototype.listen = function (...args) { this.unit.listen(); + + const cb = args.pop(); + + if (typeof cb === 'function') { + this.once('listening', cb); + } + + this.emit('listening'); + + return this; }; Server.prototype.emit_request = function (req, res) { -- cgit