From de179e90d3e1e40a4443760700648665188450ce Mon Sep 17 00:00:00 2001 From: John Livingston Date: Wed, 24 Aug 2022 11:03:29 +0200 Subject: [PATCH] Promisify proxy close. --- server/lib/prosody/ctl.ts | 4 ++-- server/lib/routers/webchat.ts | 30 +++++++++++++++++++++++------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/server/lib/prosody/ctl.ts b/server/lib/prosody/ctl.ts index e03f25b3..3e6013c7 100644 --- a/server/lib/prosody/ctl.ts +++ b/server/lib/prosody/ctl.ts @@ -188,7 +188,7 @@ async function ensureProsodyRunning (options: RegisterServerOptions): Promise { try { @@ -312,22 +312,38 @@ async function initWebchatRouter (options: RegisterServerOptions): Promise { + return new Promise((resolve) => { + try { + currentProsodyProxyInfo = null + if (!currentHttpBindProxy) { + resolve() + return + } + peertubeHelpers.logger.debug('Closing the proxy...') + currentHttpBindProxy.close(() => { + peertubeHelpers.logger.debug('The proxy is closed.') + resolve() + }) + currentHttpBindProxy = null + } catch (err) { + peertubeHelpers.logger.error('Seems that the http bind proxy close has failed: ' + (err as string)) + resolve() + } + }) } -function enableProxyRoute ( +async function enableProxyRoute ( { peertubeHelpers }: RegisterServerOptions, prosodyProxyInfo: ProsodyProxyInfo -): void { +): Promise { const logger = peertubeHelpers.logger if (!/^\d+$/.test(prosodyProxyInfo.port)) { logger.error(`Port '${prosodyProxyInfo.port}' is not valid. Aborting.`) return } currentProsodyProxyInfo = prosodyProxyInfo + logger.debug('Creating a new http bind proxy') currentHttpBindProxy = createProxyServer({ target: 'http://localhost:' + prosodyProxyInfo.port + '/http-bind', ignorePath: true