Better typing.

This commit is contained in:
John Livingston 2021-04-09 19:39:40 +02:00
parent dcef708370
commit 8b3763761b
3 changed files with 9 additions and 26 deletions

View File

@ -1,24 +1,15 @@
import type { NextFunction, Request, Response } from 'express'
import { initWebchatRouter } from './webchat'
type InitRoutersOptions = Pick<RegisterServerOptions, 'settingsManager' | 'getRouter' | 'peertubeHelpers'>
async function initRouters (options: RegisterServerOptions): Promise<void> {
const { getRouter } = options
async function initRouters ({
settingsManager,
getRouter,
peertubeHelpers
}: InitRoutersOptions): Promise<void> {
const router = getRouter()
router.get('/ping', (req: Request, res: Response, _next: NextFunction) => res.json({ message: 'pong' }))
router.use('/webchat', await initWebchatRouter({
getRouter,
peertubeHelpers,
settingsManager
}))
router.use('/webchat', await initWebchatRouter(options))
}
export {
InitRoutersOptions,
initRouters
}

View File

@ -1,4 +1,3 @@
import type { InitRoutersOptions } from './index'
import type { Router, Request, Response, NextFunction } from 'express'
import * as path from 'path'
const fs = require('fs').promises
@ -7,7 +6,7 @@ async function initWebchatRouter ({
getRouter,
peertubeHelpers,
settingsManager
}: InitRoutersOptions): Promise<Router> {
}: RegisterServerOptions): Promise<Router> {
const converseJSIndex = await fs.readFile(path.resolve(__dirname, '../../conversejs/index.html'))
const router = getRouter()

View File

@ -5,20 +5,13 @@ import decache from 'decache'
let logger: Logger | undefined
async function register ({
registerSetting,
settingsManager,
getRouter,
peertubeHelpers
}: RegisterServerOptions): Promise<any> {
async function register (options: RegisterServerOptions): Promise<any> {
const { peertubeHelpers } = options
logger = peertubeHelpers.logger
await initSettings({ registerSetting })
await initRouters({
settingsManager,
getRouter,
peertubeHelpers
})
await initSettings(options)
await initRouters(options)
}
async function unregister (): Promise<any> {