Promisify proxy close.
This commit is contained in:
parent
1bb202d9d3
commit
de179e90d3
@ -188,7 +188,7 @@ async function ensureProsodyRunning (options: RegisterServerOptions): Promise<vo
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Set the http-bind route.
|
// Set the http-bind route.
|
||||||
enableProxyRoute(options, {
|
await enableProxyRoute(options, {
|
||||||
host: config.host,
|
host: config.host,
|
||||||
port: config.port
|
port: config.port
|
||||||
})
|
})
|
||||||
@ -241,7 +241,7 @@ async function ensureProsodyNotRunning (options: RegisterServerOptions): Promise
|
|||||||
logger.info(`ProsodyCtl command returned: ${status.message}`)
|
logger.info(`ProsodyCtl command returned: ${status.message}`)
|
||||||
|
|
||||||
logger.debug('Removing proxy route')
|
logger.debug('Removing proxy route')
|
||||||
disableProxyRoute(options)
|
await disableProxyRoute(options)
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
@ -206,7 +206,7 @@ async function initWebchatRouter (options: RegisterServerOptions): Promise<Route
|
|||||||
}
|
}
|
||||||
))
|
))
|
||||||
|
|
||||||
disableProxyRoute(options)
|
await disableProxyRoute(options)
|
||||||
router.all('/http-bind',
|
router.all('/http-bind',
|
||||||
(req: Request, res: Response, next: NextFunction) => {
|
(req: Request, res: Response, next: NextFunction) => {
|
||||||
try {
|
try {
|
||||||
@ -312,22 +312,38 @@ async function initWebchatRouter (options: RegisterServerOptions): Promise<Route
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
function disableProxyRoute (_options: RegisterServerOptions): void {
|
async function disableProxyRoute ({ peertubeHelpers }: RegisterServerOptions): Promise<void> {
|
||||||
currentHttpBindProxy?.close()
|
return new Promise((resolve) => {
|
||||||
currentHttpBindProxy = null
|
try {
|
||||||
currentProsodyProxyInfo = null
|
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,
|
{ peertubeHelpers }: RegisterServerOptions,
|
||||||
prosodyProxyInfo: ProsodyProxyInfo
|
prosodyProxyInfo: ProsodyProxyInfo
|
||||||
): void {
|
): Promise<void> {
|
||||||
const logger = peertubeHelpers.logger
|
const logger = peertubeHelpers.logger
|
||||||
if (!/^\d+$/.test(prosodyProxyInfo.port)) {
|
if (!/^\d+$/.test(prosodyProxyInfo.port)) {
|
||||||
logger.error(`Port '${prosodyProxyInfo.port}' is not valid. Aborting.`)
|
logger.error(`Port '${prosodyProxyInfo.port}' is not valid. Aborting.`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
currentProsodyProxyInfo = prosodyProxyInfo
|
currentProsodyProxyInfo = prosodyProxyInfo
|
||||||
|
logger.debug('Creating a new http bind proxy')
|
||||||
currentHttpBindProxy = createProxyServer({
|
currentHttpBindProxy = createProxyServer({
|
||||||
target: 'http://localhost:' + prosodyProxyInfo.port + '/http-bind',
|
target: 'http://localhost:' + prosodyProxyInfo.port + '/http-bind',
|
||||||
ignorePath: true
|
ignorePath: true
|
||||||
|
Loading…
Reference in New Issue
Block a user