Skip to content

Commit 43b5f2a

Browse files
authored
Merge pull request #39 from CS3219-AY2425S1/PEER-214
PEER-214 Add Collaboration Service WS Server
2 parents 734a0f4 + 23031a9 commit 43b5f2a

34 files changed

+7872
-10600
lines changed

.env.local

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ QUESTION_PGDATA="/data/qn-db"
1010

1111
COLLAB_SERVICE_NAME=collab-express
1212
COLLAB_EXPRESS_PORT=9003
13+
COLLAB_EXPRESS_DB_PORT=5435
14+
COLLAB_PGDATA="/data/collab-db"
1315

1416
MATCHING_SERVICE_NAME=match-express
1517
MATCHING_EXPRESS_PORT=9004

.github/workflows/build-docker.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
name: Build & publish PeerPrep images
22
on:
33
pull_request:
4-
types: [review_requested, ready_for_review]
4+
types:
5+
- opened
6+
- reopened
7+
- synchronize
8+
- ready_for_review
59
push:
610
branches:
711
- main
@@ -16,6 +20,7 @@ env:
1620

1721
jobs:
1822
changes:
23+
if: ${{ !github.event.pull_request.draft }}
1924
runs-on: ubuntu-latest
2025
# Required permissions
2126
permissions:

backend/collaboration/.env.compose

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,9 @@
22
# PEERPREP_UI_HOST="http://frontend:3000"
33

44
EXPRESS_PORT=9003
5+
EXPRESS_DB_HOST="collab-db"
6+
EXPRESS_DB_PORT=5435
7+
POSTGRES_DB="collab"
8+
POSTGRES_USER="peerprep-collab-express"
9+
POSTGRES_PASSWORD="6rYE0nIzI2ThzDO"
10+
PGDATA="/data/collab-db"

backend/collaboration/.env.docker

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1-
PEERPREP_UI_HOST="http://host.docker.internal:5173"
1+
PEERPREP_UI_HOST=http://host.docker.internal:5173
22

33
EXPRESS_PORT=9003
4+
EXPRESS_DB_HOST=host.docker.internal
5+
EXPRESS_DB_PORT=5435
6+
POSTGRES_DB=collab
7+
POSTGRES_USER=peerprep-collab-express
8+
POSTGRES_PASSWORD=6rYE0nIzI2ThzDO
9+
PGDATA=/data/collab-db

backend/collaboration/.env.local

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
PEERPREP_UI_HOST="http://localhost:5173"
22

33
EXPRESS_PORT=9003
4+
EXPRESS_DB_HOST="localhost"
5+
EXPRESS_DB_PORT=5435
6+
POSTGRES_DB="collab"
7+
POSTGRES_USER="peerprep-collab-express"
8+
POSTGRES_PASSWORD="6rYE0nIzI2ThzDO"
9+
PGDATA="/data/collab-db"
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
11
#!/bin/sh
2-
3-
# To insert WS/RTC health checks
4-
5-
npm run start
2+
npm run start

backend/collaboration/express.Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ FROM node:lts-alpine AS build
22
WORKDIR /data/collab-express
33
COPY package*.json ./
44
RUN npm install
5+
ARG env
56
COPY . .
67
RUN npm run build
78

@@ -12,6 +13,8 @@ COPY --from=build --chown=node:node /data/collab-express/dist ./dist
1213

1314
RUN npm ci --omit=dev
1415

16+
RUN sed -i 's|./ws|ws|g' ./dist/ws.js
17+
1518
COPY entrypoint.sh .
1619

1720
ARG port

backend/collaboration/package.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,23 @@
1919
"cors": "^2.8.5",
2020
"dotenv": "^16.4.5",
2121
"env-cmd": "^10.1.0",
22-
"express": "^4.21.0",
22+
"express": "^4.21.1",
2323
"http-status-codes": "^2.3.0",
24+
"pg": "^8.13.0",
2425
"pino": "^9.4.0",
25-
"pino-http": "^10.3.0"
26+
"pino-http": "^10.3.0",
27+
"postgres": "^3.4.4",
28+
"redis": "^4.7.0",
29+
"ws": "^8.18.0",
30+
"y-postgresql": "^1.0.0",
31+
"y-websocket": "^2.0.4",
32+
"yjs": "^13.6.19"
2633
},
2734
"devDependencies": {
2835
"@types/cors": "^2.8.17",
2936
"@types/express": "^4.17.21",
3037
"@types/node": "^22.5.5",
38+
"@types/ws": "^8.5.12",
3139
"nodemon": "^3.1.4",
3240
"pino-pretty": "^11.2.2",
3341
"ts-node": "^10.9.2",

backend/collaboration/src/config.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,14 @@ import 'dotenv/config';
33
export const UI_HOST = process.env.PEERPREP_UI_HOST!;
44

55
export const EXPRESS_PORT = process.env.EXPRESS_PORT;
6+
7+
export const dbConfig = {
8+
host: process.env.EXPRESS_DB_HOST!,
9+
port: Number.parseInt(process.env.EXPRESS_DB_PORT!),
10+
database: process.env.POSTGRES_DB!,
11+
user: process.env.POSTGRES_USER,
12+
password: process.env.POSTGRES_PASSWORD,
13+
};
14+
15+
// disable gc when using snapshots!
16+
export const GC_ENABLED = process.env.GC !== 'false' && process.env.GC !== '0';
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import type { Request, Response } from 'express';
2+
import { StatusCodes } from 'http-status-codes';
3+
4+
import { getCollabRoomService } from '@/service/get/collab-get-service';
5+
import type { IGetCollabRoomPayload } from '@/service/get/types';
6+
7+
export async function getCollabRoom(req: Request, res: Response) {
8+
const { userid1, userid2, questionid } = req.query;
9+
const payload: IGetCollabRoomPayload = {
10+
userid1: userid1 as string,
11+
userid2: userid2 as string,
12+
questionid: questionid as string,
13+
};
14+
try {
15+
const result = await getCollabRoomService(payload);
16+
if (result.error) {
17+
return res.status(result.code).json({
18+
error: result.error.message ?? 'An error occurred',
19+
});
20+
}
21+
return res.status(result.code).json(result.data);
22+
} catch (err) {
23+
return res
24+
.status(StatusCodes.INTERNAL_SERVER_ERROR)
25+
.json({ success: false, message: 'An error occurred', err });
26+
}
27+
}

0 commit comments

Comments
 (0)