2021-04-08 00:43:13 +00:00
|
|
|
import { initSettings } from './lib/settings'
|
2021-04-09 17:29:44 +00:00
|
|
|
import { initRouters } from './lib/routers/index'
|
2021-04-08 01:47:55 +00:00
|
|
|
import type { Logger } from 'winston'
|
2021-04-09 09:22:46 +00:00
|
|
|
import decache from 'decache'
|
2021-04-08 01:47:55 +00:00
|
|
|
|
|
|
|
let logger: Logger | undefined
|
2021-04-07 14:52:38 +00:00
|
|
|
|
2021-04-09 17:39:40 +00:00
|
|
|
async function register (options: RegisterServerOptions): Promise<any> {
|
|
|
|
const { peertubeHelpers } = options
|
|
|
|
|
2021-04-08 01:47:55 +00:00
|
|
|
logger = peertubeHelpers.logger
|
|
|
|
|
2021-04-09 17:39:40 +00:00
|
|
|
await initSettings(options)
|
|
|
|
await initRouters(options)
|
2019-07-16 14:39:36 +00:00
|
|
|
}
|
|
|
|
|
2021-04-07 15:20:28 +00:00
|
|
|
async function unregister (): Promise<any> {
|
2021-04-08 01:47:55 +00:00
|
|
|
const module = __filename
|
|
|
|
logger?.info(`Unloading module ${module}...`)
|
2021-04-09 08:54:51 +00:00
|
|
|
// In peertube <= 3.1.0 sub modules are not removed from require.cache
|
2021-04-08 01:47:55 +00:00
|
|
|
decache(module)
|
|
|
|
logger?.info(`Successfully unloaded the module ${module}`)
|
2021-04-09 08:54:51 +00:00
|
|
|
logger = undefined
|
2019-07-16 14:39:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
register,
|
|
|
|
unregister
|
|
|
|
}
|