mirror of
https://github.com/docmost/docmost.git
synced 2025-11-15 11:31:15 +10:00
feat: add stats to standalone collab server (#798)
* Log APP_URL on startup * add stats endpoint to standalone collab server
This commit is contained in:
@ -16,6 +16,7 @@ import { HistoryListener } from './listeners/history.listener';
|
|||||||
PersistenceExtension,
|
PersistenceExtension,
|
||||||
HistoryListener,
|
HistoryListener,
|
||||||
],
|
],
|
||||||
|
exports: [CollaborationGateway],
|
||||||
imports: [TokenModule],
|
imports: [TokenModule],
|
||||||
})
|
})
|
||||||
export class CollaborationModule implements OnModuleInit, OnModuleDestroy {
|
export class CollaborationModule implements OnModuleInit, OnModuleDestroy {
|
||||||
|
|||||||
@ -7,6 +7,7 @@ import { DatabaseModule } from '@docmost/db/database.module';
|
|||||||
import { QueueModule } from '../../integrations/queue/queue.module';
|
import { QueueModule } from '../../integrations/queue/queue.module';
|
||||||
import { EventEmitterModule } from '@nestjs/event-emitter';
|
import { EventEmitterModule } from '@nestjs/event-emitter';
|
||||||
import { HealthModule } from '../../integrations/health/health.module';
|
import { HealthModule } from '../../integrations/health/health.module';
|
||||||
|
import { CollaborationController } from './collaboration.controller';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
@ -17,7 +18,12 @@ import { HealthModule } from '../../integrations/health/health.module';
|
|||||||
HealthModule,
|
HealthModule,
|
||||||
EventEmitterModule.forRoot(),
|
EventEmitterModule.forRoot(),
|
||||||
],
|
],
|
||||||
controllers: [AppController],
|
controllers: [
|
||||||
|
AppController,
|
||||||
|
...(process.env.COLLAB_SHOW_STATS.toLowerCase() === 'true'
|
||||||
|
? [CollaborationController]
|
||||||
|
: []),
|
||||||
|
],
|
||||||
providers: [AppService],
|
providers: [AppService],
|
||||||
})
|
})
|
||||||
export class CollabAppAppModule {}
|
export class CollabAppModule {}
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { NestFactory } from '@nestjs/core';
|
import { NestFactory } from '@nestjs/core';
|
||||||
import { CollabAppAppModule } from './collab-app.module';
|
import { CollabAppModule } from './collab-app.module';
|
||||||
import {
|
import {
|
||||||
FastifyAdapter,
|
FastifyAdapter,
|
||||||
NestFastifyApplication,
|
NestFastifyApplication,
|
||||||
@ -10,7 +10,7 @@ import { Logger } from '@nestjs/common';
|
|||||||
|
|
||||||
async function bootstrap() {
|
async function bootstrap() {
|
||||||
const app = await NestFactory.create<NestFastifyApplication>(
|
const app = await NestFactory.create<NestFastifyApplication>(
|
||||||
CollabAppAppModule,
|
CollabAppModule,
|
||||||
new FastifyAdapter({
|
new FastifyAdapter({
|
||||||
ignoreTrailingSlash: true,
|
ignoreTrailingSlash: true,
|
||||||
ignoreDuplicateSlashes: true,
|
ignoreDuplicateSlashes: true,
|
||||||
|
|||||||
@ -0,0 +1,15 @@
|
|||||||
|
import { Controller, Get } from '@nestjs/common';
|
||||||
|
import { CollaborationGateway } from '../collaboration.gateway';
|
||||||
|
|
||||||
|
@Controller('collab')
|
||||||
|
export class CollaborationController {
|
||||||
|
constructor(private readonly collaborationGateway: CollaborationGateway) {}
|
||||||
|
|
||||||
|
@Get('stats')
|
||||||
|
async getStats() {
|
||||||
|
return {
|
||||||
|
connections: this.collaborationGateway.getConnectionCount(),
|
||||||
|
documents: this.collaborationGateway.getDocumentCount(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -4,7 +4,7 @@ import {
|
|||||||
FastifyAdapter,
|
FastifyAdapter,
|
||||||
NestFastifyApplication,
|
NestFastifyApplication,
|
||||||
} from '@nestjs/platform-fastify';
|
} from '@nestjs/platform-fastify';
|
||||||
import { NotFoundException, ValidationPipe } from '@nestjs/common';
|
import { Logger, NotFoundException, ValidationPipe } from '@nestjs/common';
|
||||||
import { TransformHttpResponseInterceptor } from './common/interceptors/http-response.interceptor';
|
import { TransformHttpResponseInterceptor } from './common/interceptors/http-response.interceptor';
|
||||||
import fastifyMultipart from '@fastify/multipart';
|
import fastifyMultipart from '@fastify/multipart';
|
||||||
import { WsRedisIoAdapter } from './ws/adapter/ws-redis.adapter';
|
import { WsRedisIoAdapter } from './ws/adapter/ws-redis.adapter';
|
||||||
@ -65,7 +65,14 @@ async function bootstrap() {
|
|||||||
app.useGlobalInterceptors(new TransformHttpResponseInterceptor());
|
app.useGlobalInterceptors(new TransformHttpResponseInterceptor());
|
||||||
app.enableShutdownHooks();
|
app.enableShutdownHooks();
|
||||||
|
|
||||||
await app.listen(process.env.PORT || 3000, '0.0.0.0');
|
const logger = new Logger('NestApplication');
|
||||||
|
|
||||||
|
const port = process.env.PORT || 3000;
|
||||||
|
await app.listen(port, '0.0.0.0', () => {
|
||||||
|
logger.log(
|
||||||
|
`Listening on http://127.0.0.1:${port} / ${process.env.APP_URL}`,
|
||||||
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
bootstrap();
|
bootstrap();
|
||||||
|
|||||||
Reference in New Issue
Block a user