From 7314161de20d87d0c5cd717b94a4623046d688aa Mon Sep 17 00:00:00 2001 From: shrpne Date: Tue, 29 Aug 2023 21:16:30 +0100 Subject: [PATCH] add option to reuse http.Server --- Server.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Server.js b/Server.js index 0eec7a4..68a0028 100644 --- a/Server.js +++ b/Server.js @@ -25,6 +25,7 @@ var util = require('util'), * @param {Object} [options] will be passed to net.createServer() or tls.createServer() * @param {Array} [options.validProtocols] * @param {SelectProtocolCallback} [options.selectProtocol] + * @param {net.Server} [options.server] * @param {Function} [callback] will be added as "connection" listener * @inherits EventEmitter * @event listening @@ -57,7 +58,12 @@ function Server(secure, options, callback) { conn.on('error', nop) } - if (secure) { + if (options && options.server instanceof net.Server) { + this.socket = options.server + // Listening to upgrade is required for http.Server not closing connection + this.socket.on('upgrade', nop) + this.socket.on('connection', onConnection) + } else if (secure) { this.socket = tls.createServer(options, onConnection) } else { this.socket = net.createServer(options, onConnection)