Compare commits

...

1 commit

Author SHA1 Message Date
Acid Chicken (硫酸鶏)
3cf5e4fabc
wip 2023-06-15 15:40:14 +09:00
8 changed files with 665 additions and 147 deletions

View file

@ -65,9 +65,13 @@
"@fastify/multipart": "7.6.0",
"@fastify/static": "6.10.2",
"@fastify/view": "7.4.1",
"@nestjs/common": "9.4.2",
"@nestjs/core": "9.4.2",
"@nestjs/testing": "9.4.2",
"@mercuriusjs/gateway": "2.0.0",
"@nestjs/common": "9.4.3",
"@nestjs/core": "9.4.3",
"@nestjs/graphql": "11.0.6",
"@nestjs/mercurius": "11.0.6",
"@nestjs/platform-fastify": "9.4.3",
"@nestjs/testing": "9.4.3",
"@peertube/http-signature": "1.7.0",
"@sinonjs/fake-timers": "10.2.0",
"@swc/cli": "0.1.62",
@ -96,6 +100,7 @@
"fluent-ffmpeg": "2.1.2",
"form-data": "4.0.0",
"got": "12.6.0",
"graphql": "16.6.0",
"happy-dom": "9.20.3",
"hpagent": "1.2.0",
"ioredis": "5.3.2",
@ -107,6 +112,7 @@
"jsonld": "8.2.0",
"jsrsasign": "10.8.6",
"meilisearch": "0.32.5",
"mercurius": "13.0.0",
"mfm-js": "0.23.3",
"mime-types": "2.1.35",
"misskey-js": "workspace:*",

View file

@ -1,4 +1,5 @@
import { NestFactory } from '@nestjs/core';
import { FastifyAdapter, type NestFastifyApplication } from '@nestjs/platform-fastify';
import { ChartManagementService } from '@/core/chart/ChartManagementService.js';
import { QueueProcessorService } from '@/queue/QueueProcessorService.js';
import { NestLogger } from '@/NestLogger.js';
@ -10,7 +11,10 @@ import { ServerService } from '@/server/ServerService.js';
import { MainModule } from '@/MainModule.js';
export async function server() {
const app = await NestFactory.createApplicationContext(MainModule, {
const app = await NestFactory.create<NestFastifyApplication>(MainModule, new FastifyAdapter({
trustProxy: true,
logger: !['production', 'test'].includes(process.env.NODE_ENV ?? ''),
}), {
logger: new NestLogger(),
});
app.enableShutdownHooks();

View file

@ -1,5 +1,6 @@
import { Module } from '@nestjs/common';
import { EndpointsModule } from '@/server/api/EndpointsModule.js';
import { GraphQLModule } from '@/server/graphql/GraphQLModule.js';
import { CoreModule } from '@/core/CoreModule.js';
import { ApiCallService } from './api/ApiCallService.js';
import { FileServerService } from './FileServerService.js';
@ -40,6 +41,7 @@ import { RoleTimelineChannelService } from './api/stream/channels/role-timeline.
@Module({
imports: [
EndpointsModule,
GraphQLModule,
CoreModule,
],
providers: [

View file

@ -2,7 +2,7 @@ import cluster from 'node:cluster';
import * as fs from 'node:fs';
import { fileURLToPath } from 'node:url';
import { Inject, Injectable, OnApplicationShutdown } from '@nestjs/common';
import Fastify, { FastifyInstance } from 'fastify';
import { HttpAdapterHost } from '@nestjs/core';
import fastifyStatic from '@fastify/static';
import { IsNull } from 'typeorm';
import { GlobalEventService } from '@/core/GlobalEventService.js';
@ -24,13 +24,14 @@ import { WellKnownServerService } from './WellKnownServerService.js';
import { FileServerService } from './FileServerService.js';
import { ClientServerService } from './web/ClientServerService.js';
import { OpenApiServerService } from './api/openapi/OpenApiServerService.js';
import type { FastifyAdapter } from '@nestjs/platform-fastify';
import type { FastifyInstance } from 'fastify/types/instance.js';
const _dirname = fileURLToPath(new URL('.', import.meta.url));
@Injectable()
export class ServerService implements OnApplicationShutdown {
private logger: Logger;
#fastify: FastifyInstance;
constructor(
@Inject(DI.config)
@ -45,6 +46,7 @@ export class ServerService implements OnApplicationShutdown {
@Inject(DI.emojisRepository)
private emojisRepository: EmojisRepository,
private adapterHost: HttpAdapterHost<FastifyAdapter>,
private userEntityService: UserEntityService,
private apiServerService: ApiServerService,
private openApiServerService: OpenApiServerService,
@ -62,11 +64,7 @@ export class ServerService implements OnApplicationShutdown {
@bindThis
public async launch() {
const fastify = Fastify({
trustProxy: true,
logger: !['production', 'test'].includes(process.env.NODE_ENV ?? ''),
});
this.#fastify = fastify;
const fastify = this.adapterHost.httpAdapter.getInstance() as FastifyInstance;
// HSTS
// 6months (15552000sec)
@ -217,15 +215,13 @@ export class ServerService implements OnApplicationShutdown {
}
});
fastify.listen({ port: this.config.port, host: '0.0.0.0' });
await fastify.ready();
await fastify.listen({ port: this.config.port, host: '0.0.0.0' });
}
@bindThis
public async dispose(): Promise<void> {
await this.streamingApiServerService.detach();
await this.#fastify.close();
await this.streamingApiServerService.detach();
await this.adapterHost.httpAdapter.getInstance().close();
}
@bindThis

View file

@ -0,0 +1,23 @@
import path from 'node:path';
import { Module } from '@nestjs/common';
import * as nestjs_graphql from '@nestjs/graphql';
import { MercuriusDriver, MercuriusDriverConfig } from '@nestjs/mercurius';
import type { HttpAdapterHost } from '@nestjs/core';
import type { FastifyAdapter } from '@nestjs/platform-fastify';
@Module({
imports: [
nestjs_graphql.GraphQLModule.forRoot<MercuriusDriverConfig>({
driver: MercuriusDriver,
autoSchemaFile: path.join(path.dirname(import.meta.url), 'schema.graphql'),
graphiql: true,
}),
],
})
export class GraphQLModule {
constructor(
private adapterHost: HttpAdapterHost<FastifyAdapter>,
) {
console.log(adapterHost.httpAdapter.getInstance().printRoutes());
}
}

View file

@ -670,11 +670,6 @@ export class ClientServerService {
reply.header('Cache-Control', 'private, max-age=0');
});
// Render base html for all requests
fastify.get('*', async (request, reply) => {
return await renderBase(reply);
});
fastify.setErrorHandler(async (error, request, reply) => {
const errId = uuid();
this.clientLoggerService.logger.error(`Internal error occured in ${request.routerPath}: ${error.message}`, {

View file

@ -28,7 +28,7 @@
"autosize": "6.0.1",
"broadcast-channel": "5.1.0",
"browser-image-resizer": "github:misskey-dev/browser-image-resizer#v2.2.1-misskey.3",
"buraha": "github:misskey-dev/buraha",
"buraha": "0.0.1",
"canvas-confetti": "1.6.0",
"chart.js": "4.3.0",
"chartjs-adapter-date-fns": "3.0.0",

File diff suppressed because it is too large Load diff