Skip to content

Commit 4d178d4

Browse files
authored
Merge pull request #79 from CS3219-AY2425S1/development
Milestone D4
2 parents c4539a3 + 14a2277 commit 4d178d4

File tree

106 files changed

+11714
-572
lines changed

Some content is hidden

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

106 files changed

+11714
-572
lines changed

.github/workflows/ci.yml

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,33 @@ on:
77

88
env:
99
NODE_VERSION: 20
10-
FIREBASE_PROJECT_ID: ${{ secrets.FIREBASE_PROJECT_ID }}
11-
FIREBASE_PRIVATE_KEY: ${{ secrets.FIREBASE_PRIVATE_KEY }}
12-
FIREBASE_CLIENT_EMAIL: ${{ secrets.FIREBASE_CLIENT_EMAIL }}
13-
FIREBASE_STORAGE_BUCKET: ${{ secrets.FIREBASE_STORAGE_BUCKET }}
14-
JWT_SECRET: ${{ secrets.JWT_SECRET }}
1510

1611
permissions:
1712
contents: read
1813

1914
jobs:
20-
ci:
15+
frontend-ci:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
- name: Setting node version
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: ${{ env.NODE_VERSION }}
24+
- name: Install dependencies
25+
working-directory: frontend
26+
run: npm install
27+
- name: Linting
28+
working-directory: frontend
29+
run: npm run lint
30+
- name: Test
31+
run: docker compose -f docker-compose-test.yml run --rm test-frontend
32+
backend-ci:
2133
runs-on: ubuntu-latest
2234
strategy:
2335
matrix:
24-
service: [frontend, backend/question-service, backend/user-service]
36+
service: [question-service, user-service, matching-service]
2537
steps:
2638
- name: Checkout code
2739
uses: actions/checkout@v4
@@ -30,21 +42,16 @@ jobs:
3042
with:
3143
node-version: ${{ env.NODE_VERSION }}
3244
- name: Install dependencies
33-
working-directory: ${{ matrix.service }}
45+
working-directory: backend/${{ matrix.service }}
3446
run: npm install
3547
- name: Linting
36-
working-directory: ${{ matrix.service }}
48+
working-directory: backend/${{ matrix.service }}
3749
run: npm run lint
38-
- name: Set .env variables
39-
working-directory: ${{ matrix.service }}
40-
run: |
41-
touch .env
42-
echo "FIREBASE_PROJECT_ID=${{ env.FIREBASE_PROJECT_ID }}" >> .env
43-
echo "FIREBASE_PRIVATE_KEY=${{ env.FIREBASE_PRIVATE_KEY }}" >> .env
44-
echo "FIREBASE_CLIENT_EMAIL=${{ env.FIREBASE_CLIENT_EMAIL }}" >> .env
45-
echo "FIREBASE_CLIENT_EMAIL=${{ env.FIREBASE_CLIENT_EMAIL }}" >> .env
46-
echo "FIREBASE_STORAGE_BUCKET=${{ env.FIREBASE_STORAGE_BUCKET }}" >> .env
47-
echo "JWT_SECRET=${{ env.JWT_SECRET }}" >> .env
48-
- name: Tests
49-
working-directory: ${{ matrix.service }}
50-
run: npm test
50+
- name: Test
51+
env:
52+
FIREBASE_PROJECT_ID: ${{ secrets.FIREBASE_PROJECT_ID }}
53+
FIREBASE_PRIVATE_KEY: ${{ secrets.FIREBASE_PRIVATE_KEY }}
54+
FIREBASE_CLIENT_EMAIL: ${{ secrets.FIREBASE_CLIENT_EMAIL }}
55+
FIREBASE_STORAGE_BUCKET: ${{ secrets.FIREBASE_STORAGE_BUCKET }}
56+
JWT_SECRET: ${{ secrets.JWT_SECRET }}
57+
run: docker compose -f docker-compose-test.yml run --rm test-${{ matrix.service }}

.husky/pre-commit

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
cd ./frontend && npm run lint && npm run test
2-
cd ..
1+
cd ./frontend
2+
npm run lint
3+
npm run test -- --maxWorkers=50%
4+
cd ..
35

4-
cd ./backend/user-service && npm run lint && npm run test
5-
cd ../..
6+
cd ./backend/user-service
7+
npm run lint
8+
npm run test -- --maxWorkers=50%
9+
cd ../..
610

7-
cd ./backend/question-service && npm run lint && npm run test
11+
cd ./backend/question-service
12+
npm run lint
13+
npm run test -- --maxWorkers=50%
14+
cd ../..

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ docker-compose down
2828

2929
- User Service: http://localhost:3001
3030
- Question Service: http://localhost:3000
31+
- Matching Service: http://localhost:3002
3132
- Frontend: http://localhost:5173

backend/.env.sample

Lines changed: 0 additions & 16 deletions
This file was deleted.

backend/README.md

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,11 @@
22

33
> Before proceeding to each microservice for more instructions:
44
5-
1. Set-up either a local or cloud MongoDB.
5+
1. Set up cloud MongoDB if not using docker. We recommend this if you are just testing out each microservice separately to avoid needing to manually set up multiple instances of local MongoDB. Else, if you are using docker-compose.yml to run PeerPrep, check out the READMEs in the different backend microservices to set up the env for the local MongoDB instances.
66

7-
2. Set-up Firebase.
7+
2. Set up Firebase.
88

9-
## Setting-up local MongoDB (only if you are using Docker)
10-
11-
1. In the `backend` directory, create a copy of the `.env.sample` file and name it `.env`.
12-
13-
2. To set up credentials for the MongoDB database, update `MONGO_INITDB_ROOT_USERNAME`, `MONGO_INITDB_ROOT_PASSWORD` of the `.env` file.
14-
15-
3. Your local Mongo URI will be `mongodb://<MONGO_INITDB_ROOT_USERNAME>:<MONGO_INITDB_ROOT_PASSWORD>@mongo:27017/`. Take note of it as we will be using in the `.env` files in the various microservices later on.
16-
17-
4. You can view the MongoDB collections locally using Mongo Express. To set up Mongo Express, update `ME_CONFIG_BASICAUTH_USERNAME` and `ME_CONFIG_BASICAUTH_PASSWORD`. The username and password will be the login credentials when you access Mongo Express at http://localhost:8081.
9+
3. Follow the instructions [here](https://nodejs.org/en/download/package-manager) to set up Node v20.
1810

1911
## Setting-up cloud MongoDB (in production)
2012

@@ -95,6 +87,8 @@
9587

9688
## Setting-up Firebase
9789

90+
> For ease of testing, you can set up just one firebase to use across all the microservices that need it.
91+
9892
1. Go to https://console.firebase.google.com/u/0/.
9993

10094
2. Create a project and choose a project name. Navigate to `Storage` and click on it to activate it.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
coverage
2+
node_modules
3+
tests
4+
.env*
5+
*.md
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
NODE_ENV=development
2+
SERVICE_PORT=3002
3+
4+
ORIGINS=http://localhost:5173,http://127.0.0.1:5173
5+
6+
7+
## FOR RABBITMQ, comment out the variables under whichever use case (1) or (2) that is not applicable
8+
# (1) RabbitMq for running matching service individually
9+
RABBITMQ_ADDR=amqp://localhost:5672 #comment out if use case is (2)
10+
11+
# (2) RabbitMq for running matching service with other services using docker compose
12+
RABBITMQ_DEFAULT_USER=admin #comment out if use case is (1)
13+
RABBITMQ_DEFAULT_PASS=password #comment out if use case is (1)
14+
RABBITMQ_ADDR=amqp://admin:password@rabbitmq:5672 #comment out if use case is (1)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM node:20-alpine
2+
3+
WORKDIR /matching-service
4+
5+
COPY package*.json ./
6+
7+
RUN npm ci
8+
9+
COPY . .
10+
11+
EXPOSE 3002
12+
13+
CMD ["npm", "run", "dev"]

backend/matching-service/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Matching Service Guide
2+
3+
> Please ensure that you have completed the backend set-up [here](../README.md) before proceeding.
4+
5+
## Setting-up Matching Service
6+
7+
1. In the `matching-service` directory, create a copy of the `.env.sample` file and name it `.env`. If you are looking to run matching service with the other services using docker-compose, comment out the variable `RABBITMQ_ADDR` under use case (1) in the .env file. Otherwise, if you are looking to run matching service individually, comment out the variables `RABBITMQ_DEFAULT_USER`, `RABBITMQ_DEFAULT_PASS` and `RABBITMQ_ADDR` under use case (2) in the .env file.
8+
9+
2. If you are running matching service together with other services using docker-compose, to set up credentials for RabbitMq, update the RabbitMq variables in the `.env` file. Update `RABBITMQ_DEFAULT_USER` and `RABBITMQ_DEFAULT_PASS` to what you want, then update `RABBITMQ_ADDR` to be `amqp://<RABBITMQ_DEFAULT_USER>:<RABBITMQ_DEFAULT_PASS>@rabbitmq:5672`. You can access RabbitMq management user interface locally with the username in `RABBITMQ_DEFAULT_USER` and password in `RABBITMQ_DEFAULT_PASS` at http://localhost:15672.
10+
11+
3. If you are running matching service individually, you do not need to make any changes to `RABBITMQ_ADDR`. You can access RabbitMq management user interface locally with the username `guest` and password `guest` at http://localhost:15672.
12+
13+
## Running Matching Service Individually with Docker
14+
15+
1. Set up and run RabbitMq locally on your computer with the command `docker run -it --rm --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:4.0-management`.
16+
17+
2. Open Command Line/Terminal and navigate into the `matching-service` directory.
18+
19+
3. Run the command: `npm install`. This will install all the necessary dependencies.
20+
21+
4. Run the command `npm start` to start the Matching Service in production mode, or use `npm run dev` for development mode, which includes features like automatic server restart when you make code changes. If you encounter connection errors, please wait for a few minutes before running `npm start` again as RabbitMq may take some time to start up.
22+
23+
## After running
24+
25+
1. To view Matching Service documentation, go to http://localhost:3002/docs.
26+
27+
2. Using applications like Postman, you can interact with the Matching Service on port 3002. If you wish to change this, please update the `.env` file.

backend/matching-service/app.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import express, { Request, Response } from "express";
2+
import dotenv from "dotenv";
3+
import swaggerUi from "swagger-ui-express";
4+
import yaml from "yaml";
5+
import fs from "fs";
6+
import cors from "cors";
7+
8+
import matchingRoutes from "./src/routes/matchingRoutes.ts";
9+
10+
dotenv.config();
11+
12+
export const allowedOrigins = process.env.ORIGINS
13+
? process.env.ORIGINS.split(",")
14+
: ["http://localhost:5173", "http://127.0.0.1:5173"];
15+
16+
const file = fs.readFileSync("./swagger.yml", "utf-8");
17+
const swaggerDocument = yaml.parse(file);
18+
19+
const app = express();
20+
21+
app.use(cors({ origin: allowedOrigins, credentials: true }));
22+
app.options("*", cors({ origin: allowedOrigins, credentials: true }));
23+
24+
app.use("/api/matching", matchingRoutes);
25+
app.use("/docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument));
26+
app.get("/", (req: Request, res: Response) => {
27+
res.status(200).json({ message: "Hello world from matching service" });
28+
});
29+
30+
export default app;

0 commit comments

Comments
 (0)