@@ -29,6 +29,7 @@ function debugLog(...args) {
|
||||
let proxyServer = null;
|
||||
let proxyPort = null;
|
||||
let proxyCertsDirOrCA = null; // saved so restart() can regenerate the cert
|
||||
const proxyConnections = new Set(); // track live sockets so stop() can force-close them
|
||||
/** Resolver: hostname -> { host, port } or port number (then host defaults to 127.0.0.1) or null */
|
||||
let getBackendForHostname = null;
|
||||
|
||||
@@ -98,6 +99,11 @@ function start(port, certsDirOrCA, callback, baseDomains) {
|
||||
proxyServer = https.createServer(opts, onRequest);
|
||||
// Forward WebSocket upgrade requests to the backend tunnel
|
||||
proxyServer.on('upgrade', onUpgrade);
|
||||
// Track live connections so stop() can force-close them for instant restart
|
||||
proxyServer.on('connection', (socket) => {
|
||||
proxyConnections.add(socket);
|
||||
socket.once('close', () => proxyConnections.delete(socket));
|
||||
});
|
||||
} catch (err) {
|
||||
if (process.stderr) process.stderr.write('[https-proxy] createServer threw: ' + err.message + '\n');
|
||||
done(err);
|
||||
@@ -326,6 +332,11 @@ function stop(callback) {
|
||||
const s = proxyServer;
|
||||
proxyServer = null;
|
||||
proxyPort = null;
|
||||
// Destroy all live connections so s.close() completes immediately
|
||||
for (const socket of proxyConnections) {
|
||||
try { socket.destroy(); } catch (_) {}
|
||||
}
|
||||
proxyConnections.clear();
|
||||
s.close(() => {
|
||||
if (callback) callback();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user