summaryrefslogtreecommitdiff
path: root/packages/backend/src/server/web/ClientServerService.ts
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2022-12-04 17:33:51 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2022-12-04 17:33:51 +0900
commitc0c23b135c036326b5c846d7c4d2d07753520ec2 (patch)
tree7dfaddc448c79f07b15e1142a0d85822f6c3ef76 /packages/backend/src/server/web/ClientServerService.ts
parentchore: fix import position (diff)
downloadsharkey-c0c23b135c036326b5c846d7c4d2d07753520ec2.tar.gz
sharkey-c0c23b135c036326b5c846d7c4d2d07753520ec2.tar.bz2
sharkey-c0c23b135c036326b5c846d7c4d2d07753520ec2.zip
bull-board復活
Diffstat (limited to 'packages/backend/src/server/web/ClientServerService.ts')
-rw-r--r--packages/backend/src/server/web/ClientServerService.ts23
1 files changed, 13 insertions, 10 deletions
diff --git a/packages/backend/src/server/web/ClientServerService.ts b/packages/backend/src/server/web/ClientServerService.ts
index 727cf92831..ae776adf18 100644
--- a/packages/backend/src/server/web/ClientServerService.ts
+++ b/packages/backend/src/server/web/ClientServerService.ts
@@ -2,6 +2,9 @@ import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { PathOrFileDescriptor, readFileSync } from 'node:fs';
import { Inject, Injectable } from '@nestjs/common';
+import { createBullBoard } from '@bull-board/api';
+import { BullAdapter } from '@bull-board/api/bullAdapter.js';
+import { FastifyAdapter } from '@bull-board/fastify';
import ms from 'ms';
import sharp from 'sharp';
import pug from 'pug';
@@ -9,6 +12,7 @@ import { In, IsNull } from 'typeorm';
import { FastifyInstance, FastifyPluginOptions, FastifyReply } from 'fastify';
import fastifyStatic from '@fastify/static';
import fastifyView from '@fastify/view';
+import fastifyCookie from '@fastify/cookie';
import type { Config } from '@/config.js';
import { getNoteSummary } from '@/misc/get-note-summary.js';
import { DI } from '@/di-symbols.js';
@@ -100,28 +104,28 @@ export class ClientServerService {
@bindThis
public createServer(fastify: FastifyInstance, options: FastifyPluginOptions, done: (err?: Error) => void) {
- /* TODO
+ fastify.register(fastifyCookie, {});
+
//#region Bull Dashboard
const bullBoardPath = '/queue';
// Authenticate
- app.use(async (request, reply) => {
- if (ctx.path === bullBoardPath || ctx.path.startsWith(bullBoardPath + '/')) {
- const token = ctx.cookies.get('token');
+ fastify.addHook('onRequest', async (request, reply) => {
+ if (request.url === bullBoardPath || request.url.startsWith(bullBoardPath + '/')) {
+ const token = request.cookies.token;
if (token == null) {
reply.code(401);
- return;
+ throw new Error('login required');
}
const user = await this.usersRepository.findOneBy({ token });
if (user == null || !(user.isAdmin || user.isModerator)) {
reply.code(403);
- return;
+ throw new Error('access denied');
}
}
- await next();
});
- const serverAdapter = new KoaAdapter();
+ const serverAdapter = new FastifyAdapter();
createBullBoard({
queues: [
@@ -137,9 +141,8 @@ export class ClientServerService {
});
serverAdapter.setBasePath(bullBoardPath);
- app.use(serverAdapter.registerPlugin());
+ fastify.register(serverAdapter.registerPlugin(), { prefix: bullBoardPath });
//#endregion
- */
fastify.register(fastifyView, {
root: _dirname + '/views',