summaryrefslogtreecommitdiff
path: root/packages/backend/src/server/NodeinfoServerService.ts
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2022-12-03 19:42:05 +0900
committerGitHub <noreply@github.com>2022-12-03 19:42:05 +0900
commit3a7182bfb5734599321fc03ea77c48b4dbc326d5 (patch)
treec96c46e0a9662809c40381d833e1ed1ca28de873 /packages/backend/src/server/NodeinfoServerService.ts
parentUpdate CHANGELOG.md (diff)
downloadsharkey-3a7182bfb5734599321fc03ea77c48b4dbc326d5.tar.gz
sharkey-3a7182bfb5734599321fc03ea77c48b4dbc326d5.tar.bz2
sharkey-3a7182bfb5734599321fc03ea77c48b4dbc326d5.zip
Fastify (#9106)
* wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * fix * Update SignupApiService.ts * wip * wip * Update ClientServerService.ts * wip * wip * wip * Update WellKnownServerService.ts * wip * wip * update des * wip * Update ApiServerService.ts * wip * update deps * Update WellKnownServerService.ts * wip * update deps * Update ApiCallService.ts * Update ApiCallService.ts * Update ApiServerService.ts
Diffstat (limited to 'packages/backend/src/server/NodeinfoServerService.ts')
-rw-r--r--packages/backend/src/server/NodeinfoServerService.ts21
1 files changed, 10 insertions, 11 deletions
diff --git a/packages/backend/src/server/NodeinfoServerService.ts b/packages/backend/src/server/NodeinfoServerService.ts
index ef4ec74a35..b85925f53e 100644
--- a/packages/backend/src/server/NodeinfoServerService.ts
+++ b/packages/backend/src/server/NodeinfoServerService.ts
@@ -1,5 +1,5 @@
import { Inject, Injectable } from '@nestjs/common';
-import Router from '@koa/router';
+import { FastifyInstance, FastifyPluginOptions, FastifyReply, FastifyRequest } from 'fastify';
import { IsNull, MoreThan } from 'typeorm';
import { DI } from '@/di-symbols.js';
import type { NotesRepository, UsersRepository } from '@/models/index.js';
@@ -27,6 +27,7 @@ export class NodeinfoServerService {
private userEntityService: UserEntityService,
private metaService: MetaService,
) {
+ this.createServer = this.createServer.bind(this);
}
public getLinks() {
@@ -39,9 +40,7 @@ export class NodeinfoServerService {
}];
}
- public createRouter() {
- const router = new Router();
-
+ public createServer(fastify: FastifyInstance, options: FastifyPluginOptions, done: (err?: Error) => void) {
const nodeinfo2 = async () => {
const now = Date.now();
const [
@@ -108,22 +107,22 @@ export class NodeinfoServerService {
const cache = new Cache<Awaited<ReturnType<typeof nodeinfo2>>>(1000 * 60 * 10);
- router.get(nodeinfo2_1path, async ctx => {
+ fastify.get(nodeinfo2_1path, async (request, reply) => {
const base = await cache.fetch(null, () => nodeinfo2());
- ctx.body = { version: '2.1', ...base };
- ctx.set('Cache-Control', 'public, max-age=600');
+ reply.header('Cache-Control', 'public, max-age=600');
+ return { version: '2.1', ...base };
});
- router.get(nodeinfo2_0path, async ctx => {
+ fastify.get(nodeinfo2_0path, async (request, reply) => {
const base = await cache.fetch(null, () => nodeinfo2());
delete (base as any).software.repository;
- ctx.body = { version: '2.0', ...base };
- ctx.set('Cache-Control', 'public, max-age=600');
+ reply.header('Cache-Control', 'public, max-age=600');
+ return { version: '2.0', ...base };
});
- return router;
+ done();
}
}