summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMax Romanov <max.romanov@nginx.com>2020-04-08 14:44:53 +0300
committerMax Romanov <max.romanov@nginx.com>2020-04-08 14:44:53 +0300
commitce53d6bdb1a61de0f81dad39a978dec92e286071 (patch)
treeace4710a389859cf885dfb98e07c3d71d2cc1f25
parent792ef9d3c71c6843dbbde450a2d6d1ade538f1f3 (diff)
downloadunit-ce53d6bdb1a61de0f81dad39a978dec92e286071.tar.gz
unit-ce53d6bdb1a61de0f81dad39a978dec92e286071.tar.bz2
Node.js: fixing Server.listen() method.
This is required for Express framework compatibility. This closes #418 issue on GitHub.
-rw-r--r--src/nodejs/unit-http/http_server.js12
1 files changed, 11 insertions, 1 deletions
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) {