Skip to content

Commit ea3f356

Browse files
committed
feature/split api websocket
1 parent c83e59d commit ea3f356

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+2414
-4
lines changed

docker-compose.override.yml

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,41 @@ services:
2222
timeout: 5s
2323
retries: 3
2424
command: --bind-address=0.0.0.0
25+
26+
collaborative:
27+
build:
28+
context: .
29+
dockerfile: ./packages/collaborative/Dockerfile
30+
container_name: collaborative
31+
ports:
32+
- "3001:3001"
33+
- "9001:9001"
34+
depends_on:
35+
mysql:
36+
condition: service_healthy
37+
mongodb:
38+
condition: service_healthy
39+
environment:
40+
- MYSQL_HOST=mysql-container
41+
- MYSQL_PORT=3306
42+
- MYSQL_DATABASE=dev_db
43+
- MYSQL_PASSWORD=1234
44+
- MYSQL_USER=honey
45+
- NODE_ENV=dev
46+
- MONGO_HOST=mongodb-container
47+
- MONGO_USER=honey
48+
- MONGO_PASSWORD=1234
49+
- MONGO_DB=dev_db
50+
- LOG_LEVEL=info
51+
networks:
52+
- app-network
2553
api:
2654
build:
2755
context: .
2856
dockerfile: ./packages/api/Dockerfile
2957
container_name: api
3058
ports:
3159
- "3000:3000"
32-
- "9001:9001"
3360
depends_on:
3461
mysql:
3562
condition: service_healthy
@@ -58,6 +85,8 @@ services:
5885
ports:
5986
- "80:80"
6087
depends_on:
88+
collaborative:
89+
condition: service_started
6190
api:
6291
condition: service_started
6392
networks:

packages/api/src/app.module.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { getMongooseConfig } from './common/config/mongo.config';
88
import { getTypeOrmConfig } from './common/config/typeorm.config';
99
import { NoteModule } from './note/note.module';
1010
import { SpaceModule } from './space/space.module';
11-
import { YjsModule } from './yjs/yjs.module';
1211
import { TestModule } from './test/test.module';
1312

1413
@Module({
@@ -25,7 +24,6 @@ import { TestModule } from './test/test.module';
2524
useFactory: getTypeOrmConfig,
2625
}),
2726
SpaceModule,
28-
YjsModule,
2927
NoteModule,
3028
TestModule,
3129
CollaborativeModule,

packages/collaborative/.gitignore

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# compiled output
2+
/dist
3+
/node_modules
4+
/build
5+
6+
# Logs
7+
logs
8+
*.log
9+
npm-debug.log*
10+
pnpm-debug.log*
11+
yarn-debug.log*
12+
yarn-error.log*
13+
lerna-debug.log*
14+
15+
# OS
16+
.DS_Store
17+
18+
# Tests
19+
/coverage
20+
/.nyc_output
21+
a.env
22+
# IDEs and editors
23+
/.idea
24+
.project
25+
.classpath
26+
.c9/
27+
*.launch
28+
.settings/
29+
*.sublime-workspace
30+
31+
# IDE - VSCode
32+
.vscode/*
33+
!.vscode/settings.json
34+
!.vscode/tasks.json
35+
!.vscode/launch.json
36+
!.vscode/extensions.json
37+
38+
# dotenv environment variable files
39+
.env
40+
.env.development.local
41+
.env.test.local
42+
.env.production.local
43+
.env.local
44+
.env.prod
45+
46+
# temp directory
47+
.temp
48+
.tmp
49+
50+
# Runtime data
51+
pids
52+
*.pid
53+
*.seed
54+
*.pid.lock
55+
56+
# Diagnostic reports (https://nodejs.org/api/report.html)
57+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

packages/collaborative/.prettierrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "all",
4+
"endOfLine": "auto"
5+
}

packages/collaborative/Dockerfile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FROM node:20-alpine AS builder
2+
3+
WORKDIR /app
4+
5+
RUN apk add --no-cache python3 make g++ && npm install -g pnpm
6+
COPY package.json pnpm-workspace.yaml pnpm-lock.yaml ./
7+
COPY ./packages/collaborative ./packages/collaborative/
8+
COPY ./packages/shared ./packages/shared/
9+
10+
RUN HUSKY=0 pnpm install --frozen-lockfile
11+
12+
RUN cd ./packages/collaborative && pnpm build
13+
14+
FROM node:20-alpine AS production
15+
16+
WORKDIR /app
17+
18+
COPY --from=builder /app .
19+
20+
WORKDIR /app/packages/collaborative
21+
22+
EXPOSE 3000
23+
24+
CMD ["node", "dist/main"]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"$schema": "https://json.schemastore.org/nest-cli",
3+
"collection": "@nestjs/schematics",
4+
"sourceRoot": "src",
5+
"compilerOptions": {
6+
"deleteOutDir": true
7+
}
8+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
{
2+
"name": "collaborative",
3+
"version": "0.0.1",
4+
"description": "",
5+
"author": "",
6+
"private": true,
7+
"license": "UNLICENSED",
8+
"scripts": {
9+
"build": "nest build",
10+
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
11+
"start": "nest start",
12+
"start:dev": "nest start --watch",
13+
"start:debug": "nest start --debug --watch",
14+
"start:prod": "node dist/collaborative/src/main.js",
15+
"test": "jest",
16+
"test:watch": "jest --watch",
17+
"test:cov": "jest --coverage",
18+
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
19+
"test:e2e": "jest --config ./test/jest-e2e.json"
20+
},
21+
"dependencies": {
22+
"@elastic/elasticsearch": "^8.16.1",
23+
"@nestjs/cache-manager": "^2.3.0",
24+
"@nestjs/common": "^10.4.7",
25+
"@nestjs/config": "^3.3.0",
26+
"@nestjs/core": "^10.4.7",
27+
"@nestjs/elasticsearch": "^10.0.2",
28+
"@nestjs/mongoose": "^10.1.0",
29+
"@nestjs/platform-express": "^10.0.0",
30+
"@nestjs/platform-socket.io": "^10.4.8",
31+
"@nestjs/platform-ws": "^10.4.8",
32+
"@nestjs/schedule": "^4.1.1",
33+
"@nestjs/swagger": "^8.0.7",
34+
"@nestjs/terminus": "^10.2.3",
35+
"@nestjs/typeorm": "^10.0.2",
36+
"@nestjs/websockets": "^10.4.8",
37+
"dotenv": "^16.4.5",
38+
"mongoose": "^8.8.1",
39+
"mysql2": "^3.11.4",
40+
"nest-winston": "^1.9.7",
41+
"prosemirror": "^0.11.1",
42+
"reflect-metadata": "^0.2.2",
43+
"rxjs": "^7.8.1",
44+
"shared": "workspace:*",
45+
"socket.io": "^4.8.1",
46+
"swagger-ui-express": "^5.0.1",
47+
"typeorm": "^0.3.20",
48+
"utils": "link:@milkdown/kit/utils",
49+
"uuid": "^11.0.3",
50+
"winston": "^3.17.0",
51+
"winston-daily-rotate-file": "^5.0.0",
52+
"ws": "^8.18.0",
53+
"y-socket.io": "^1.1.3",
54+
"y-websocket": "^2.0.4",
55+
"yjs": "^13.6.20"
56+
},
57+
"devDependencies": {
58+
"@nestjs/cli": "^10.0.0",
59+
"@nestjs/schematics": "^10.0.0",
60+
"@nestjs/testing": "^10.0.0",
61+
"@types/express": "^5.0.0",
62+
"@types/jest": "^29.5.2",
63+
"@types/mongoose": "^5.11.97",
64+
"@types/node": "^20.17.6",
65+
"@types/socket.io": "^3.0.2",
66+
"@types/supertest": "^6.0.0",
67+
"@types/uuid": "^10.0.0",
68+
"@types/ws": "^8.5.13",
69+
"jest": "^29.5.0",
70+
"prettier": "^3.0.0",
71+
"source-map-support": "^0.5.21",
72+
"supertest": "^7.0.0",
73+
"ts-jest": "^29.1.0",
74+
"ts-loader": "^9.4.3",
75+
"ts-node": "^10.9.2",
76+
"tsconfig-paths": "^4.2.0",
77+
"typescript": "^5.6.3"
78+
},
79+
"jest": {
80+
"moduleFileExtensions": [
81+
"js",
82+
"json",
83+
"ts"
84+
],
85+
"rootDir": "src",
86+
"testRegex": ".*\\.spec\\.ts$",
87+
"transform": {
88+
"^.+\\.(t|j)s$": "ts-jest"
89+
},
90+
"collectCoverageFrom": [
91+
"**/*.(t|j)s"
92+
],
93+
"coverageDirectory": "../coverage",
94+
"testEnvironment": "node"
95+
}
96+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { Logger, Module, OnModuleInit } from '@nestjs/common';
2+
import { ConfigModule, ConfigService } from '@nestjs/config';
3+
import { MongooseModule } from '@nestjs/mongoose';
4+
import { TypeOrmModule } from '@nestjs/typeorm';
5+
6+
import { CollaborativeModule } from './collaborative/collaborative.module';
7+
import { getMongooseConfig } from './common/config/mongo.config';
8+
import { getTypeOrmConfig } from './common/config/typeorm.config';
9+
import { NoteModule } from './note/note.module';
10+
import { SpaceModule } from './space/space.module';
11+
import { YjsModule } from './yjs/yjs.module';
12+
import { TestModule } from './test/test.module';
13+
14+
@Module({
15+
imports: [
16+
ConfigModule.forRoot({
17+
isGlobal: true,
18+
}),
19+
MongooseModule.forRootAsync({
20+
inject: [ConfigService],
21+
useFactory: getMongooseConfig,
22+
}),
23+
TypeOrmModule.forRootAsync({
24+
inject: [ConfigService],
25+
useFactory: getTypeOrmConfig,
26+
}),
27+
SpaceModule,
28+
YjsModule,
29+
NoteModule,
30+
TestModule,
31+
CollaborativeModule,
32+
],
33+
})
34+
export class AppModule implements OnModuleInit {
35+
private readonly logger = new Logger(AppModule.name);
36+
37+
async onModuleInit(): Promise<void> {
38+
this.logger.debug('Application initialized for debug');
39+
this.logger.log('Application initialized', {
40+
module: 'AppModule',
41+
environment: process.env.NODE_ENV ?? 'development',
42+
timestamp: new Date().toISOString(),
43+
});
44+
}
45+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Module } from '@nestjs/common';
2+
3+
import { NoteModule } from '../note/note.module';
4+
import { SpaceModule } from '../space/space.module';
5+
import { CollaborativeService } from './collaborative.service';
6+
7+
@Module({
8+
imports: [NoteModule, SpaceModule],
9+
providers: [CollaborativeService],
10+
exports: [CollaborativeService],
11+
})
12+
export class CollaborativeModule {}

0 commit comments

Comments
 (0)