Routers in separate files.
This commit is contained in:
parent
1728e52e9f
commit
dcef708370
24
server/lib/routers/index.ts
Normal file
24
server/lib/routers/index.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import type { NextFunction, Request, Response } from 'express'
|
||||
import { initWebchatRouter } from './webchat'
|
||||
|
||||
type InitRoutersOptions = Pick<RegisterServerOptions, 'settingsManager' | 'getRouter' | 'peertubeHelpers'>
|
||||
|
||||
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
|
||||
}))
|
||||
}
|
||||
|
||||
export {
|
||||
InitRoutersOptions,
|
||||
initRouters
|
||||
}
|
@ -1,19 +1,17 @@
|
||||
import type { InitRoutersOptions } from './index'
|
||||
import type { Router, Request, Response, NextFunction } from 'express'
|
||||
import * as path from 'path'
|
||||
import type { NextFunction, Request, Response } from 'express'
|
||||
const fs = require('fs').promises
|
||||
|
||||
type InitRoutersOptions = Pick<RegisterServerOptions, 'settingsManager' | 'getRouter' | 'peertubeHelpers'>
|
||||
|
||||
export async function initRouters ({
|
||||
settingsManager,
|
||||
async function initWebchatRouter ({
|
||||
getRouter,
|
||||
peertubeHelpers
|
||||
}: InitRoutersOptions): Promise<void> {
|
||||
const converseJSIndex = await fs.readFile(path.resolve(__dirname, '../conversejs/index.html'))
|
||||
peertubeHelpers,
|
||||
settingsManager
|
||||
}: InitRoutersOptions): Promise<Router> {
|
||||
const converseJSIndex = await fs.readFile(path.resolve(__dirname, '../../conversejs/index.html'))
|
||||
|
||||
const router = getRouter()
|
||||
router.get('/ping', (req: Request, res: Response) => res.json({ message: 'pong' }))
|
||||
router.get('/webchat', async (req: Request, res: Response, next: NextFunction) => {
|
||||
router.get('/', async (req: Request, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
const settings = await settingsManager.getSettings([
|
||||
'chat-use-builtin', 'chat-room', 'chat-server',
|
||||
@ -70,4 +68,9 @@ export async function initRouters ({
|
||||
return next(error)
|
||||
}
|
||||
})
|
||||
return router
|
||||
}
|
||||
|
||||
export {
|
||||
initWebchatRouter
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
import { initSettings } from './lib/settings'
|
||||
import { initRouters } from './lib/routers'
|
||||
import { initRouters } from './lib/routers/index'
|
||||
import type { Logger } from 'winston'
|
||||
import decache from 'decache'
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user