From 8b3763761b3affdbe2d379fb5603922d45bda62d Mon Sep 17 00:00:00 2001 From: John Livingston Date: Fri, 9 Apr 2021 19:39:40 +0200 Subject: [PATCH] Better typing. --- server/lib/routers/index.ts | 15 +++------------ server/lib/routers/webchat.ts | 3 +-- server/main.ts | 17 +++++------------ 3 files changed, 9 insertions(+), 26 deletions(-) diff --git a/server/lib/routers/index.ts b/server/lib/routers/index.ts index 6dea168a..f918f1c8 100644 --- a/server/lib/routers/index.ts +++ b/server/lib/routers/index.ts @@ -1,24 +1,15 @@ import type { NextFunction, Request, Response } from 'express' import { initWebchatRouter } from './webchat' -type InitRoutersOptions = Pick +async function initRouters (options: RegisterServerOptions): Promise { + const { getRouter } = options -async function initRouters ({ - settingsManager, - getRouter, - peertubeHelpers -}: InitRoutersOptions): Promise { 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 } diff --git a/server/lib/routers/webchat.ts b/server/lib/routers/webchat.ts index cb0c2430..e7a9ed62 100644 --- a/server/lib/routers/webchat.ts +++ b/server/lib/routers/webchat.ts @@ -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 { +}: RegisterServerOptions): Promise { const converseJSIndex = await fs.readFile(path.resolve(__dirname, '../../conversejs/index.html')) const router = getRouter() diff --git a/server/main.ts b/server/main.ts index a5e086d9..1cc4f4a6 100644 --- a/server/main.ts +++ b/server/main.ts @@ -5,20 +5,13 @@ import decache from 'decache' let logger: Logger | undefined -async function register ({ - registerSetting, - settingsManager, - getRouter, - peertubeHelpers -}: RegisterServerOptions): Promise { +async function register (options: RegisterServerOptions): Promise { + const { peertubeHelpers } = options + logger = peertubeHelpers.logger - await initSettings({ registerSetting }) - await initRouters({ - settingsManager, - getRouter, - peertubeHelpers - }) + await initSettings(options) + await initRouters(options) } async function unregister (): Promise {