Skip to content

Commit

Permalink
Revert "Revert "URGENT JWT Fixes: Backend Storage, Bugs""
Browse files Browse the repository at this point in the history
  • Loading branch information
juslam19 authored Nov 13, 2023
1 parent 231ff82 commit adef7f4
Show file tree
Hide file tree
Showing 26 changed files with 494 additions and 414 deletions.
4 changes: 3 additions & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
{}
{
"endOfLine": "lf"
}
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
# PeerPrep G17

## Overview

An interview preparation platform designed to facilitate live coding sessions between peers.

## Repository Structure

The repository consists of a [frontend](https://github.com/CS3219-AY2324S1/ay2324s1-course-assessment-g17/tree/master/frontend) and multiple microservices on the [backend](https://github.com/CS3219-AY2324S1/ay2324s1-course-assessment-g17/tree/master/backend), each serving a specific purpose to enhance the overall interview preparation experience.

```bash
.
├── frontend
├── backend
│ ├── question-service
│ ├── question-service
│ ├── user-service
│ ├── matching-service
│ ├── collaboration-service
│ ├── forum-service
│ ├── chat-service
│ ├── chat-service
│ ├── help-service
│ └── api-gateway
├── serverless
Expand All @@ -24,21 +26,25 @@ The repository consists of a [frontend](https://github.com/CS3219-AY2324S1/ay232
```

## Setup

### Local Deployment

Ensure that you have the following:

- [Docker](https://docs.docker.com/get-docker/)
- Environment variables configured for the respective microservices

### Instructions

1. Clone the repository.
2. Set up the environment variables for the microservices.
3. Run `docker-compose up` in the root directory of the repository.
4. Access the frontend by navigating to `localhost:3000` in your browser.

## Deployment
PeerPrep is deployed on both AWS and GCP for scalability and reliability.

PeerPrep is deployed on both AWS and GCP for scalability and reliability.

- The frontend is deployed on AWS Amplify.
- The backend is deployed on GCP Cloud Run, question storage (MongoDB Atlas), relational database needs (AWS RDS), RabbitMQ for message queuing (AWS EC2) and serverless functions for question scraping (GCP Cloud Functions, Cloud Scheduler).
- The backend is deployed on GCP Cloud Run, question storage (MongoDB Atlas), relational database needs (AWS RDS), RabbitMQ for message queuing (AWS EC2) and serverless functions for question scraping (GCP Cloud Functions, Cloud Scheduler).
- CI is done using GitHub Actions.

16 changes: 8 additions & 8 deletions backend/api-gateway/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FROM nginx

WORKDIR /app

COPY nginx.conf .

CMD ["nginx", "-c", "/app/nginx.conf", "-g", "daemon off;"]

FROM nginx

WORKDIR /app

COPY nginx.conf .

CMD ["nginx", "-c", "/app/nginx.conf", "-g", "daemon off;"]

30 changes: 15 additions & 15 deletions backend/collaboration-service/Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
FROM node:18

WORKDIR /usr/src/app

RUN npm install -g nodemon
RUN npm install -g ts-node

COPY package*.json ./

RUN npm install

COPY . .

EXPOSE 8082

FROM node:18
WORKDIR /usr/src/app
RUN npm install -g nodemon
RUN npm install -g ts-node
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 8082
CMD ["ts-node", "./app.ts"]
3 changes: 3 additions & 0 deletions backend/forum-service/.env.docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
POSTGRESQL_DATABASE_URL="postgresql://postgres:postgres@localhost:5432/forum?schema=public"
PORT=9001
FRONTEND_URL="http://localhost:3000"
2 changes: 1 addition & 1 deletion backend/help-service/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ app.get(
const output = result[0]["candidates"]![0]["output"];
res.send(output);
});
}
},
);

app.listen(port, () => {
Expand Down
32 changes: 16 additions & 16 deletions backend/matching-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
FROM node:18

RUN npm install -g nodemon

WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install --frozen-lockfile

COPY . .

EXPOSE 9000

CMD ["npm", "start"]

FROM node:18

RUN npm install -g nodemon

WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install --frozen-lockfile

COPY . .

EXPOSE 9000

CMD ["npm", "start"]

Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ export async function findMatch(matchingInfo: MatchingInfo) {
...potentialMatch.toObject(),
categories: findIntersection(
potentialMatch.categories,
matchingInfo.topics
matchingInfo.topics,
),
difficulty_levels: findIntersection(
potentialMatch.difficulty_levels,
matchingInfo.difficulty_level
matchingInfo.difficulty_level,
),
};

Expand All @@ -119,6 +119,6 @@ export async function markAsTimeout(matchingInfo: MatchingInfo) {
socket_id: matchingInfo.socket_id,
status: MatchStatusEnum.PENDING,
},
{ status: MatchStatusEnum.TIMEOUT }
{ status: MatchStatusEnum.TIMEOUT },
);
}
16 changes: 12 additions & 4 deletions backend/question-service/src/middleware/authMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import { Request, Response, NextFunction } from "express";
import { authenticateAccessToken } from "../utils/jwt";

interface User {
export interface User {
id: number;
password: string;
username: string;
email: string;
role: string;
languages: string[];
languages: { id: number; language: string }[];
githubId?: number;
}

interface JwtPayload {
user: User;
export interface UserWithoutPassword {
id: number;
role: string;
}

export interface JwtPayload {
user: UserWithoutPassword;
exp: number;
iat: number;
}
Expand All @@ -25,6 +32,7 @@ export async function verifyAccessToken(
next();
return;
}

const accessToken = req.cookies["accessToken"]; // If JWT token is stored in a cookie

if (!accessToken) {
Expand Down
Loading

0 comments on commit adef7f4

Please sign in to comment.