mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-23 00:53:08 +02:00
wip
This commit is contained in:
parent
f5dfb64a52
commit
3cf5e4fabc
8 changed files with 665 additions and 147 deletions
|
@ -65,9 +65,13 @@
|
||||||
"@fastify/multipart": "7.6.0",
|
"@fastify/multipart": "7.6.0",
|
||||||
"@fastify/static": "6.10.2",
|
"@fastify/static": "6.10.2",
|
||||||
"@fastify/view": "7.4.1",
|
"@fastify/view": "7.4.1",
|
||||||
"@nestjs/common": "9.4.2",
|
"@mercuriusjs/gateway": "2.0.0",
|
||||||
"@nestjs/core": "9.4.2",
|
"@nestjs/common": "9.4.3",
|
||||||
"@nestjs/testing": "9.4.2",
|
"@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",
|
"@peertube/http-signature": "1.7.0",
|
||||||
"@sinonjs/fake-timers": "10.2.0",
|
"@sinonjs/fake-timers": "10.2.0",
|
||||||
"@swc/cli": "0.1.62",
|
"@swc/cli": "0.1.62",
|
||||||
|
@ -96,6 +100,7 @@
|
||||||
"fluent-ffmpeg": "2.1.2",
|
"fluent-ffmpeg": "2.1.2",
|
||||||
"form-data": "4.0.0",
|
"form-data": "4.0.0",
|
||||||
"got": "12.6.0",
|
"got": "12.6.0",
|
||||||
|
"graphql": "16.6.0",
|
||||||
"happy-dom": "9.20.3",
|
"happy-dom": "9.20.3",
|
||||||
"hpagent": "1.2.0",
|
"hpagent": "1.2.0",
|
||||||
"ioredis": "5.3.2",
|
"ioredis": "5.3.2",
|
||||||
|
@ -107,6 +112,7 @@
|
||||||
"jsonld": "8.2.0",
|
"jsonld": "8.2.0",
|
||||||
"jsrsasign": "10.8.6",
|
"jsrsasign": "10.8.6",
|
||||||
"meilisearch": "0.32.5",
|
"meilisearch": "0.32.5",
|
||||||
|
"mercurius": "13.0.0",
|
||||||
"mfm-js": "0.23.3",
|
"mfm-js": "0.23.3",
|
||||||
"mime-types": "2.1.35",
|
"mime-types": "2.1.35",
|
||||||
"misskey-js": "workspace:*",
|
"misskey-js": "workspace:*",
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { NestFactory } from '@nestjs/core';
|
import { NestFactory } from '@nestjs/core';
|
||||||
|
import { FastifyAdapter, type NestFastifyApplication } from '@nestjs/platform-fastify';
|
||||||
import { ChartManagementService } from '@/core/chart/ChartManagementService.js';
|
import { ChartManagementService } from '@/core/chart/ChartManagementService.js';
|
||||||
import { QueueProcessorService } from '@/queue/QueueProcessorService.js';
|
import { QueueProcessorService } from '@/queue/QueueProcessorService.js';
|
||||||
import { NestLogger } from '@/NestLogger.js';
|
import { NestLogger } from '@/NestLogger.js';
|
||||||
|
@ -10,7 +11,10 @@ import { ServerService } from '@/server/ServerService.js';
|
||||||
import { MainModule } from '@/MainModule.js';
|
import { MainModule } from '@/MainModule.js';
|
||||||
|
|
||||||
export async function server() {
|
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(),
|
logger: new NestLogger(),
|
||||||
});
|
});
|
||||||
app.enableShutdownHooks();
|
app.enableShutdownHooks();
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
import { EndpointsModule } from '@/server/api/EndpointsModule.js';
|
import { EndpointsModule } from '@/server/api/EndpointsModule.js';
|
||||||
|
import { GraphQLModule } from '@/server/graphql/GraphQLModule.js';
|
||||||
import { CoreModule } from '@/core/CoreModule.js';
|
import { CoreModule } from '@/core/CoreModule.js';
|
||||||
import { ApiCallService } from './api/ApiCallService.js';
|
import { ApiCallService } from './api/ApiCallService.js';
|
||||||
import { FileServerService } from './FileServerService.js';
|
import { FileServerService } from './FileServerService.js';
|
||||||
|
@ -40,6 +41,7 @@ import { RoleTimelineChannelService } from './api/stream/channels/role-timeline.
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
EndpointsModule,
|
EndpointsModule,
|
||||||
|
GraphQLModule,
|
||||||
CoreModule,
|
CoreModule,
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
|
|
|
@ -2,7 +2,7 @@ import cluster from 'node:cluster';
|
||||||
import * as fs from 'node:fs';
|
import * as fs from 'node:fs';
|
||||||
import { fileURLToPath } from 'node:url';
|
import { fileURLToPath } from 'node:url';
|
||||||
import { Inject, Injectable, OnApplicationShutdown } from '@nestjs/common';
|
import { Inject, Injectable, OnApplicationShutdown } from '@nestjs/common';
|
||||||
import Fastify, { FastifyInstance } from 'fastify';
|
import { HttpAdapterHost } from '@nestjs/core';
|
||||||
import fastifyStatic from '@fastify/static';
|
import fastifyStatic from '@fastify/static';
|
||||||
import { IsNull } from 'typeorm';
|
import { IsNull } from 'typeorm';
|
||||||
import { GlobalEventService } from '@/core/GlobalEventService.js';
|
import { GlobalEventService } from '@/core/GlobalEventService.js';
|
||||||
|
@ -24,13 +24,14 @@ import { WellKnownServerService } from './WellKnownServerService.js';
|
||||||
import { FileServerService } from './FileServerService.js';
|
import { FileServerService } from './FileServerService.js';
|
||||||
import { ClientServerService } from './web/ClientServerService.js';
|
import { ClientServerService } from './web/ClientServerService.js';
|
||||||
import { OpenApiServerService } from './api/openapi/OpenApiServerService.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));
|
const _dirname = fileURLToPath(new URL('.', import.meta.url));
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ServerService implements OnApplicationShutdown {
|
export class ServerService implements OnApplicationShutdown {
|
||||||
private logger: Logger;
|
private logger: Logger;
|
||||||
#fastify: FastifyInstance;
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(DI.config)
|
@Inject(DI.config)
|
||||||
|
@ -45,6 +46,7 @@ export class ServerService implements OnApplicationShutdown {
|
||||||
@Inject(DI.emojisRepository)
|
@Inject(DI.emojisRepository)
|
||||||
private emojisRepository: EmojisRepository,
|
private emojisRepository: EmojisRepository,
|
||||||
|
|
||||||
|
private adapterHost: HttpAdapterHost<FastifyAdapter>,
|
||||||
private userEntityService: UserEntityService,
|
private userEntityService: UserEntityService,
|
||||||
private apiServerService: ApiServerService,
|
private apiServerService: ApiServerService,
|
||||||
private openApiServerService: OpenApiServerService,
|
private openApiServerService: OpenApiServerService,
|
||||||
|
@ -62,11 +64,7 @@ export class ServerService implements OnApplicationShutdown {
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
public async launch() {
|
public async launch() {
|
||||||
const fastify = Fastify({
|
const fastify = this.adapterHost.httpAdapter.getInstance() as FastifyInstance;
|
||||||
trustProxy: true,
|
|
||||||
logger: !['production', 'test'].includes(process.env.NODE_ENV ?? ''),
|
|
||||||
});
|
|
||||||
this.#fastify = fastify;
|
|
||||||
|
|
||||||
// HSTS
|
// HSTS
|
||||||
// 6months (15552000sec)
|
// 6months (15552000sec)
|
||||||
|
@ -217,15 +215,13 @@ export class ServerService implements OnApplicationShutdown {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.listen({ port: this.config.port, host: '0.0.0.0' });
|
await fastify.listen({ port: this.config.port, host: '0.0.0.0' });
|
||||||
|
|
||||||
await fastify.ready();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
public async dispose(): Promise<void> {
|
public async dispose(): Promise<void> {
|
||||||
await this.streamingApiServerService.detach();
|
await this.streamingApiServerService.detach();
|
||||||
await this.#fastify.close();
|
await this.adapterHost.httpAdapter.getInstance().close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
|
|
23
packages/backend/src/server/graphql/GraphQLModule.ts
Normal file
23
packages/backend/src/server/graphql/GraphQLModule.ts
Normal 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());
|
||||||
|
}
|
||||||
|
}
|
|
@ -670,11 +670,6 @@ export class ClientServerService {
|
||||||
reply.header('Cache-Control', 'private, max-age=0');
|
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) => {
|
fastify.setErrorHandler(async (error, request, reply) => {
|
||||||
const errId = uuid();
|
const errId = uuid();
|
||||||
this.clientLoggerService.logger.error(`Internal error occured in ${request.routerPath}: ${error.message}`, {
|
this.clientLoggerService.logger.error(`Internal error occured in ${request.routerPath}: ${error.message}`, {
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
"autosize": "6.0.1",
|
"autosize": "6.0.1",
|
||||||
"broadcast-channel": "5.1.0",
|
"broadcast-channel": "5.1.0",
|
||||||
"browser-image-resizer": "github:misskey-dev/browser-image-resizer#v2.2.1-misskey.3",
|
"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",
|
"canvas-confetti": "1.6.0",
|
||||||
"chart.js": "4.3.0",
|
"chart.js": "4.3.0",
|
||||||
"chartjs-adapter-date-fns": "3.0.0",
|
"chartjs-adapter-date-fns": "3.0.0",
|
||||||
|
|
742
pnpm-lock.yaml
742
pnpm-lock.yaml
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue