mirror of
https://github.com/docmost/docmost.git
synced 2026-05-08 23:33:09 +08:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d51342f7b0 | |||
| 7d034e8a8b | |||
| 81b6c7ef69 | |||
| 89f6b0a8c2 | |||
| ad1571b902 | |||
| 4b9ab4f63c | |||
| 08829ea721 | |||
| 6c502b4749 |
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "client",
|
"name": "client",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.8.2",
|
"version": "0.8.3",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build": "tsc && vite build",
|
"build": "tsc && vite build",
|
||||||
|
|||||||
@@ -19,15 +19,13 @@ export function getBackendUrl(): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getCollaborationUrl(): string {
|
export function getCollaborationUrl(): string {
|
||||||
const COLLAB_PATH = "/collab";
|
const baseUrl =
|
||||||
|
getConfigValue("COLLAB_URL") ||
|
||||||
|
(import.meta.env.DEV ? process.env.APP_URL : getAppUrl());
|
||||||
|
|
||||||
let url = getAppUrl();
|
const collabUrl = new URL("/collab", baseUrl);
|
||||||
if (import.meta.env.DEV) {
|
collabUrl.protocol = collabUrl.protocol === "https:" ? "wss:" : "ws:";
|
||||||
url = process.env.APP_URL;
|
return collabUrl.toString();
|
||||||
}
|
|
||||||
|
|
||||||
const wsProtocol = url.startsWith("https") ? "wss" : "ws";
|
|
||||||
return `${wsProtocol}://${url.split("://")[1]}${COLLAB_PATH}`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getAvatarUrl(avatarUrl: string) {
|
export function getAvatarUrl(avatarUrl: string) {
|
||||||
|
|||||||
@@ -5,16 +5,21 @@ import * as path from "path";
|
|||||||
export const envPath = path.resolve(process.cwd(), "..", "..");
|
export const envPath = path.resolve(process.cwd(), "..", "..");
|
||||||
|
|
||||||
export default defineConfig(({ mode }) => {
|
export default defineConfig(({ mode }) => {
|
||||||
const { APP_URL, FILE_UPLOAD_SIZE_LIMIT, DRAWIO_URL } = loadEnv(mode, envPath, "");
|
const { APP_URL, FILE_UPLOAD_SIZE_LIMIT, DRAWIO_URL, COLLAB_URL } = loadEnv(
|
||||||
|
mode,
|
||||||
|
envPath,
|
||||||
|
"",
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
define: {
|
define: {
|
||||||
"process.env": {
|
"process.env": {
|
||||||
APP_URL,
|
APP_URL,
|
||||||
FILE_UPLOAD_SIZE_LIMIT,
|
FILE_UPLOAD_SIZE_LIMIT,
|
||||||
DRAWIO_URL
|
DRAWIO_URL,
|
||||||
|
COLLAB_URL,
|
||||||
},
|
},
|
||||||
'APP_VERSION': JSON.stringify(process.env.npm_package_version),
|
APP_VERSION: JSON.stringify(process.env.npm_package_version),
|
||||||
},
|
},
|
||||||
plugins: [react()],
|
plugins: [react()],
|
||||||
resolve: {
|
resolve: {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "server",
|
"name": "server",
|
||||||
"version": "0.8.2",
|
"version": "0.8.3",
|
||||||
"description": "",
|
"description": "",
|
||||||
"author": "",
|
"author": "",
|
||||||
"private": true,
|
"private": true,
|
||||||
@@ -12,6 +12,7 @@
|
|||||||
"start:dev": "cross-env NODE_ENV=development nest start --watch",
|
"start:dev": "cross-env NODE_ENV=development nest start --watch",
|
||||||
"start:debug": "cross-env NODE_ENV=development nest start --debug --watch",
|
"start:debug": "cross-env NODE_ENV=development nest start --debug --watch",
|
||||||
"start:prod": "cross-env NODE_ENV=production node dist/main",
|
"start:prod": "cross-env NODE_ENV=production node dist/main",
|
||||||
|
"collab:prod": "cross-env NODE_ENV=production node dist/collaboration/server/collab-main",
|
||||||
"email:dev": "email dev -p 5019 -d ./src/integrations/transactional/emails",
|
"email:dev": "email dev -p 5019 -d ./src/integrations/transactional/emails",
|
||||||
"migration:create": "tsx src/database/migrate.ts create",
|
"migration:create": "tsx src/database/migrate.ts create",
|
||||||
"migration:up": "tsx src/database/migrate.ts up",
|
"migration:up": "tsx src/database/migrate.ts up",
|
||||||
@@ -47,7 +48,9 @@
|
|||||||
"@nestjs/terminus": "^11.0.0",
|
"@nestjs/terminus": "^11.0.0",
|
||||||
"@nestjs/websockets": "^11.0.10",
|
"@nestjs/websockets": "^11.0.10",
|
||||||
"@react-email/components": "0.0.28",
|
"@react-email/components": "0.0.28",
|
||||||
"@react-email/render": "^1.0.2",
|
"@react-email/render": "1.0.2",
|
||||||
|
"@sentry/nestjs": "^9.2.0",
|
||||||
|
"@sentry/profiling-node": "^9.2.0",
|
||||||
"@socket.io/redis-adapter": "^8.3.0",
|
"@socket.io/redis-adapter": "^8.3.0",
|
||||||
"bcrypt": "^5.1.1",
|
"bcrypt": "^5.1.1",
|
||||||
"bullmq": "^5.41.3",
|
"bullmq": "^5.41.3",
|
||||||
@@ -96,7 +99,7 @@
|
|||||||
"jest": "^29.7.0",
|
"jest": "^29.7.0",
|
||||||
"kysely-codegen": "^0.17.0",
|
"kysely-codegen": "^0.17.0",
|
||||||
"prettier": "^3.5.1",
|
"prettier": "^3.5.1",
|
||||||
"react-email": "^3.0.2",
|
"react-email": "3.0.2",
|
||||||
"source-map-support": "^0.5.21",
|
"source-map-support": "^0.5.21",
|
||||||
"supertest": "^7.0.0",
|
"supertest": "^7.0.0",
|
||||||
"ts-jest": "^29.2.5",
|
"ts-jest": "^29.2.5",
|
||||||
|
|||||||
@@ -14,9 +14,11 @@ import { EventEmitterModule } from '@nestjs/event-emitter';
|
|||||||
import { HealthModule } from './integrations/health/health.module';
|
import { HealthModule } from './integrations/health/health.module';
|
||||||
import { ExportModule } from './integrations/export/export.module';
|
import { ExportModule } from './integrations/export/export.module';
|
||||||
import { ImportModule } from './integrations/import/import.module';
|
import { ImportModule } from './integrations/import/import.module';
|
||||||
|
import { SentryModule } from "@sentry/nestjs/setup";
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
|
SentryModule.forRoot(),
|
||||||
CoreModule,
|
CoreModule,
|
||||||
DatabaseModule,
|
DatabaseModule,
|
||||||
EnvironmentModule,
|
EnvironmentModule,
|
||||||
|
|||||||
@@ -25,21 +25,25 @@ export class CollaborationGateway {
|
|||||||
this.redisConfig = parseRedisUrl(this.environmentService.getRedisUrl());
|
this.redisConfig = parseRedisUrl(this.environmentService.getRedisUrl());
|
||||||
|
|
||||||
this.hocuspocus = HocuspocusServer.configure({
|
this.hocuspocus = HocuspocusServer.configure({
|
||||||
debounce: 5000,
|
debounce: 10000,
|
||||||
maxDebounce: 10000,
|
maxDebounce: 20000,
|
||||||
unloadImmediately: false,
|
unloadImmediately: false,
|
||||||
extensions: [
|
extensions: [
|
||||||
this.authenticationExtension,
|
this.authenticationExtension,
|
||||||
this.persistenceExtension,
|
this.persistenceExtension,
|
||||||
new Redis({
|
...(this.environmentService.isCollabDisableRedis()
|
||||||
host: this.redisConfig.host,
|
? []
|
||||||
port: this.redisConfig.port,
|
: [
|
||||||
options: {
|
new Redis({
|
||||||
password: this.redisConfig.password,
|
host: this.redisConfig.host,
|
||||||
db: this.redisConfig.db,
|
port: this.redisConfig.port,
|
||||||
retryStrategy: createRetryStrategy(),
|
options: {
|
||||||
},
|
password: this.redisConfig.password,
|
||||||
}),
|
db: this.redisConfig.db,
|
||||||
|
retryStrategy: createRetryStrategy(),
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
]),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -48,6 +52,14 @@ export class CollaborationGateway {
|
|||||||
this.hocuspocus.handleConnection(client, request);
|
this.hocuspocus.handleConnection(client, request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getConnectionCount() {
|
||||||
|
return this.hocuspocus.getConnectionsCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
getDocumentCount() {
|
||||||
|
return this.hocuspocus.getDocumentsCount();
|
||||||
|
}
|
||||||
|
|
||||||
async destroy(): Promise<void> {
|
async destroy(): Promise<void> {
|
||||||
await this.hocuspocus.destroy();
|
await this.hocuspocus.destroy();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { AppController } from '../../app.controller';
|
||||||
|
import { AppService } from '../../app.service';
|
||||||
|
import { EnvironmentModule } from '../../integrations/environment/environment.module';
|
||||||
|
import { CollaborationModule } from '../collaboration.module';
|
||||||
|
import { DatabaseModule } from '@docmost/db/database.module';
|
||||||
|
import { QueueModule } from '../../integrations/queue/queue.module';
|
||||||
|
import { EventEmitterModule } from '@nestjs/event-emitter';
|
||||||
|
import { HealthModule } from '../../integrations/health/health.module';
|
||||||
|
import { CollaborationController } from './collaboration.controller';
|
||||||
|
import { SentryModule } from "@sentry/nestjs/setup";
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
imports: [
|
||||||
|
SentryModule.forRoot(),
|
||||||
|
DatabaseModule,
|
||||||
|
EnvironmentModule,
|
||||||
|
CollaborationModule,
|
||||||
|
QueueModule,
|
||||||
|
HealthModule,
|
||||||
|
EventEmitterModule.forRoot(),
|
||||||
|
],
|
||||||
|
controllers: [
|
||||||
|
AppController,
|
||||||
|
...(process.env.COLLAB_SHOW_STATS.toLowerCase() === 'true'
|
||||||
|
? [CollaborationController]
|
||||||
|
: []),
|
||||||
|
],
|
||||||
|
providers: [AppService],
|
||||||
|
})
|
||||||
|
export class CollabAppModule {}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
import "./common/sentry/instrument";
|
||||||
|
import { NestFactory } from '@nestjs/core';
|
||||||
|
import { CollabAppModule } from './collab-app.module';
|
||||||
|
import {
|
||||||
|
FastifyAdapter,
|
||||||
|
NestFastifyApplication,
|
||||||
|
} from '@nestjs/platform-fastify';
|
||||||
|
import { TransformHttpResponseInterceptor } from '../../common/interceptors/http-response.interceptor';
|
||||||
|
import { InternalLogFilter } from '../../common/logger/internal-log-filter';
|
||||||
|
import { Logger } from '@nestjs/common';
|
||||||
|
|
||||||
|
async function bootstrap() {
|
||||||
|
const app = await NestFactory.create<NestFastifyApplication>(
|
||||||
|
CollabAppModule,
|
||||||
|
new FastifyAdapter({
|
||||||
|
ignoreTrailingSlash: true,
|
||||||
|
ignoreDuplicateSlashes: true,
|
||||||
|
maxParamLength: 500,
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
logger: new InternalLogFilter(),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
app.setGlobalPrefix('api', { exclude: ['/'] });
|
||||||
|
|
||||||
|
app.enableCors();
|
||||||
|
|
||||||
|
app.useGlobalInterceptors(new TransformHttpResponseInterceptor());
|
||||||
|
app.enableShutdownHooks();
|
||||||
|
|
||||||
|
const logger = new Logger('CollabServer');
|
||||||
|
|
||||||
|
const port = process.env.COLLAB_PORT || 3001;
|
||||||
|
await app.listen(port, '0.0.0.0', () => {
|
||||||
|
logger.log(`Listening on http://127.0.0.1:${port}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
bootstrap();
|
||||||
@@ -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(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import * as Sentry from '@sentry/nestjs';
|
||||||
|
import { nodeProfilingIntegration } from '@sentry/profiling-node';
|
||||||
|
import { envPath } from '../helpers';
|
||||||
|
import * as dotenv from 'dotenv';
|
||||||
|
dotenv.config({ path: envPath });
|
||||||
|
|
||||||
|
if (process.env.SENTRY_DSN) {
|
||||||
|
Sentry.init({
|
||||||
|
dsn: process.env.SENTRY_DSN,
|
||||||
|
integrations: [
|
||||||
|
nodeProfilingIntegration(),
|
||||||
|
],
|
||||||
|
tracesSampleRate: 1.0,
|
||||||
|
profilesSampleRate: 1.0,
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -145,4 +145,15 @@ export class EnvironmentService {
|
|||||||
isSelfHosted(): boolean {
|
isSelfHosted(): boolean {
|
||||||
return !this.isCloud();
|
return !this.isCloud();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getCollabUrl(): string {
|
||||||
|
return this.configService.get<string>('COLLAB_URL');
|
||||||
|
}
|
||||||
|
|
||||||
|
isCollabDisableRedis(): boolean {
|
||||||
|
const isStandalone = this.configService
|
||||||
|
.get<string>('COLLAB_DISABLE_REDIS', 'false')
|
||||||
|
.toLowerCase();
|
||||||
|
return isStandalone === 'true';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import {
|
|||||||
IsOptional,
|
IsOptional,
|
||||||
IsUrl,
|
IsUrl,
|
||||||
MinLength,
|
MinLength,
|
||||||
|
ValidateIf,
|
||||||
validateSync,
|
validateSync,
|
||||||
} from 'class-validator';
|
} from 'class-validator';
|
||||||
import { plainToInstance } from 'class-transformer';
|
import { plainToInstance } from 'class-transformer';
|
||||||
@@ -48,6 +49,11 @@ export class EnvironmentVariables {
|
|||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsIn(['local', 's3'])
|
@IsIn(['local', 's3'])
|
||||||
STORAGE_DRIVER: string;
|
STORAGE_DRIVER: string;
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
@ValidateIf((obj) => obj.COLLAB_URL != '' && obj.COLLAB_URL != null)
|
||||||
|
@IsUrl({ protocols: ['http', 'https'], require_tld: false })
|
||||||
|
COLLAB_URL: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function validate(config: Record<string, any>) {
|
export function validate(config: Record<string, any>) {
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ export class StaticModule implements OnModuleInit {
|
|||||||
FILE_UPLOAD_SIZE_LIMIT:
|
FILE_UPLOAD_SIZE_LIMIT:
|
||||||
this.environmentService.getFileUploadSizeLimit(),
|
this.environmentService.getFileUploadSizeLimit(),
|
||||||
DRAWIO_URL: this.environmentService.getDrawioUrl(),
|
DRAWIO_URL: this.environmentService.getDrawioUrl(),
|
||||||
|
COLLAB_URL: this.environmentService.getCollabUrl(),
|
||||||
};
|
};
|
||||||
|
|
||||||
const windowScriptContent = `<script>window.CONFIG=${JSON.stringify(configString)};</script>`;
|
const windowScriptContent = `<script>window.CONFIG=${JSON.stringify(configString)};</script>`;
|
||||||
|
|||||||
+11
-2
@@ -1,10 +1,11 @@
|
|||||||
|
import "./common/sentry/instrument";
|
||||||
import { NestFactory } from '@nestjs/core';
|
import { NestFactory } from '@nestjs/core';
|
||||||
import { AppModule } from './app.module';
|
import { AppModule } from './app.module';
|
||||||
import {
|
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';
|
||||||
@@ -18,6 +19,7 @@ async function bootstrap() {
|
|||||||
ignoreTrailingSlash: true,
|
ignoreTrailingSlash: true,
|
||||||
ignoreDuplicateSlashes: true,
|
ignoreDuplicateSlashes: true,
|
||||||
maxParamLength: 500,
|
maxParamLength: 500,
|
||||||
|
trustProxy: true,
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
logger: new InternalLogFilter(),
|
logger: new InternalLogFilter(),
|
||||||
@@ -65,7 +67,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();
|
||||||
|
|||||||
+2
-1
@@ -1,11 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "docmost",
|
"name": "docmost",
|
||||||
"homepage": "https://docmost.com",
|
"homepage": "https://docmost.com",
|
||||||
"version": "0.8.2",
|
"version": "0.8.3",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "nx run-many -t build",
|
"build": "nx run-many -t build",
|
||||||
"start": "pnpm --filter ./apps/server run start:prod",
|
"start": "pnpm --filter ./apps/server run start:prod",
|
||||||
|
"collab": "pnpm --filter ./apps/server run collab:prod",
|
||||||
"server:build": "nx run server:build",
|
"server:build": "nx run server:build",
|
||||||
"client:build": "nx run client:build",
|
"client:build": "nx run client:build",
|
||||||
"editor-ext:build": "nx run @docmost/editor-ext:build",
|
"editor-ext:build": "nx run @docmost/editor-ext:build",
|
||||||
|
|||||||
Generated
+211
-463
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user