server: use configService

This commit is contained in:
fantasticit 2022-05-21 14:54:35 +08:00
parent c32e1f9894
commit f57e2bf23c
3 changed files with 19 additions and 4 deletions

View File

@ -8,12 +8,14 @@ import { UserModule } from '@modules/user.module';
import { ViewModule } from '@modules/view.module';
import { WikiModule } from '@modules/wiki.module';
import { forwardRef, Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { TypeOrmModule } from '@nestjs/typeorm';
import { DocumentService } from '@services/document.service';
@Module({
imports: [
TypeOrmModule.forFeature([DocumentAuthorityEntity, DocumentEntity]),
forwardRef(() => ConfigModule),
forwardRef(() => UserModule),
forwardRef(() => WikiModule),
forwardRef(() => MessageModule),

View File

@ -1,6 +1,7 @@
import { onAuthenticatePayload, onChangePayload, onLoadDocumentPayload, Server } from '@hocuspocus/server';
import { TiptapTransformer } from '@hocuspocus/transformer';
import { forwardRef, HttpException, HttpStatus, Inject, Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { DocumentService } from '@services/document.service';
import { DocumentVersionService } from '@services/document-version.service';
import { TemplateService } from '@services/template.service';
@ -26,12 +27,18 @@ export class CollaborationService {
constructor(
@Inject(forwardRef(() => UserService))
private readonly userService: UserService,
@Inject(forwardRef(() => DocumentService))
private readonly documentService: DocumentService,
@Inject(forwardRef(() => TemplateService))
private readonly templateService: TemplateService,
@Inject(forwardRef(() => DocumentVersionService))
private readonly documentVersionService: DocumentVersionService
private readonly documentVersionService: DocumentVersionService,
@Inject(forwardRef(() => ConfigService))
private readonly configService: ConfigService
) {
this.initServer();
}
@ -73,8 +80,9 @@ export class CollaborationService {
onDisconnect: this.onDisconnect.bind(this),
});
this.server = server;
await this.server.listen(lodash.get(getConfig(), 'server.collaborationPort', 5003));
console.log('[think] 协作服务启动成功');
const port = this.configService.get('server.collaborationPort') || 5003;
await this.server.listen(port);
console.log(`[think] 协作服务启动成功,端口:${port}`);
} catch (err) {
console.error('[think] 协作服务启动失败:', err.message);
}

View File

@ -5,6 +5,7 @@ import { UpdateDocumentDto } from '@dtos/update-document.dto';
import { DocumentEntity } from '@entities/document.entity';
import { DocumentAuthorityEntity } from '@entities/document-authority.entity';
import { forwardRef, HttpException, HttpStatus, Inject, Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { InjectRepository } from '@nestjs/typeorm';
import { CollaborationService } from '@services/collaboration.service';
import { DocumentVersionService } from '@services/document-version.service';
@ -30,6 +31,9 @@ export class DocumentService {
@InjectRepository(DocumentEntity)
public readonly documentRepo: Repository<DocumentEntity>,
@Inject(forwardRef(() => ConfigService))
private readonly configService: ConfigService,
@Inject(forwardRef(() => MessageService))
private readonly messageService: MessageService,
@ -50,7 +54,8 @@ export class DocumentService {
this.userService,
this,
this.templateService,
this.documentVersionService
this.documentVersionService,
this.configService
);
}