Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feedback #1

Open
wants to merge 270 commits into
base: feedback
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
270 commits
Select commit Hold shift + click to select a range
b3e5f1d
Define Question model.
Sep 23, 2024
e10f9b8
Add QuestionCategory schema and modify Question schema
Sep 23, 2024
591b91c
Define uniqueness for Question and QuestionCategory schema
Sep 23, 2024
7d940c5
Implemented Question Service Endpoint
Sep 23, 2024
b79fc00
Integrate API to frontend
jingting1412 Sep 23, 2024
3b40897
Delete .env.sample
LamJiuFong Sep 25, 2024
68d6c69
Delete Mongodb instructions
LamJiuFong Sep 25, 2024
8da5156
Delete mongodb images
LamJiuFong Sep 25, 2024
a9ecf85
Add CRUD for admin question list
jingting1412 Sep 25, 2024
6fbb2f9
Improve question page
jingting1412 Sep 25, 2024
2a735e4
Fix updating issues
jingting1412 Sep 25, 2024
cbeffc6
Fix adding issues
jingting1412 Sep 25, 2024
a487374
Merge pull request #33 from CS3219-AY2425S1/user-service-cleanup
jingting1412 Sep 27, 2024
03a0658
Merge branch 'dev' of https://github.com/CS3219-AY2425S1/cs3219-ay242…
jingting1412 Sep 27, 2024
762d443
code quality improvement
Sep 27, 2024
085f988
Merge pull request #32 from CS3219-AY2425S1/question-service-garret
LamJiuFong Sep 27, 2024
afc16ae
Merge pull request #35 from CS3219-AY2425S1/question-service
songfangyl Sep 27, 2024
73d0ed0
Update README
LamJiuFong Sep 27, 2024
feb21d9
Fix updating issues
jingting1412 Sep 27, 2024
0085dbf
Update UI
jingting1412 Sep 27, 2024
1346465
Fix issues with update
jingting1412 Sep 27, 2024
689d51a
Add button to question page on home page
jingting1412 Sep 27, 2024
4b35cae
Add basic styles
jingting1412 Sep 27, 2024
a0aa1ff
Validate password at least 8 characters
LamJiuFong Sep 27, 2024
43cf485
Merge branch 'dev' into question-ui-resolve-conflict
LamJiuFong Sep 28, 2024
c76bf20
Resolve conflict in router
LamJiuFong Sep 28, 2024
b0bab45
Sync APIs
LamJiuFong Sep 28, 2024
64eaacc
Link frontend and backend
LamJiuFong Sep 28, 2024
82af5e3
Fix difficulty rendering bug
LamJiuFong Sep 28, 2024
ac5c533
feat: get filtered questions
lyuanww Sep 28, 2024
64ba85a
Merge pull request #38 from CS3219-AY2425S1/question-svc-link-front-back
LamJiuFong Sep 28, 2024
e486e08
Merge pull request #34 from CS3219-AY2425S1/question-ui
LamJiuFong Sep 28, 2024
738be63
Merge pull request #36 from CS3219-AY2425S1/user-service-changes
songfangyl Sep 28, 2024
2582afa
feat: one option for difficulty and multiple options for category
lyuanww Sep 28, 2024
0581ecb
Merge branch 'dev' into liyuan/getting-filtered-questions
lyuanww Sep 28, 2024
0b83234
feat: add title filter
lyuanww Sep 28, 2024
ffee146
feat: change difficulty into string and add link field into questions
lyuanww Sep 28, 2024
8b9159e
minor comment fix
lyuanww Sep 28, 2024
929f0e5
Refactor 'addQuestion' to create 'creatQuestion'
songfangyl Sep 28, 2024
5509b18
Update question form, allow multiple category
songfangyl Sep 28, 2024
d568cfb
Allow user to add hints, exmaples and link for question creation
songfangyl Sep 29, 2024
eafe398
Merge pull request #41 from CS3219-AY2425S1/liyuan/getting-filtered-q…
TehOPanas Sep 29, 2024
e539e45
change to package.json
Sep 29, 2024
fbfbb9f
Merge remote-tracking branch 'origin/dev' into question-service-garret
Sep 29, 2024
8a37b5f
Add error handling for updateQuestion
Sep 29, 2024
85d2924
Render all the details, inlcuding categories,
songfangyl Sep 29, 2024
3e2b5c6
Merge branch 'question-service-garret' into frontend-create-question
songfangyl Sep 29, 2024
03c60e3
Integrate fetching question from backend
songfangyl Sep 29, 2024
8eeb956
integrate fecthing question from backend
songfangyl Sep 29, 2024
3b95c6e
integrete create question with backend
songfangyl Sep 29, 2024
5f25c17
represent difficulty with string not integer anymore
songfangyl Sep 29, 2024
e41dc17
Make all the question details show properly
songfangyl Sep 29, 2024
5114d8f
integrate update question
songfangyl Sep 29, 2024
afd9391
clean up code
songfangyl Sep 29, 2024
736ba1b
Merge pull request #47 from CS3219-AY2425S1/frontend-create-question
LamJiuFong Sep 29, 2024
94603cc
Update error message
LamJiuFong Sep 29, 2024
5d1be22
Merge pull request #48 from CS3219-AY2425S1/question-handling-error
songfangyl Sep 29, 2024
4a54005
Frontend fixes
jingting1412 Sep 29, 2024
fd21f35
Merge pull request #49 from CS3219-AY2425S1/error-handling
songfangyl Sep 29, 2024
7856f72
Trim input at controller
songfangyl Sep 29, 2024
3ef2f88
Merge pull request #50 from CS3219-AY2425S1/frontend-create-question
jingting1412 Sep 29, 2024
9c33db5
Merge pull request #51 from CS3219-AY2425S1/dev
LamJiuFong Sep 29, 2024
66a9f2a
Containerize question service, frontend
songfangyl Oct 6, 2024
2dcf47f
update README.md
songfangyl Oct 6, 2024
ce27d67
Containerize user-service
LamJiuFong Oct 6, 2024
c7cc97b
Merge pull request #53 from CS3219-AY2425S1/docker-user-service
jingting1412 Oct 6, 2024
00afd2b
Merge pull request #52 from CS3219-AY2425S1/containarize-question-ser…
jingting1412 Oct 6, 2024
e26d86a
Merge pull request #54 from CS3219-AY2425S1/dev
LamJiuFong Oct 6, 2024
b236cfd
setup: matching
lyuanww Oct 10, 2024
b2752b6
add search bar component
songfangyl Oct 11, 2024
d18c6df
add api function for filtering
songfangyl Oct 11, 2024
ef4cde0
add spinner for loading
songfangyl Oct 11, 2024
47dd223
Integrate filtering feature
songfangyl Oct 11, 2024
b54f5fa
style the search bar
songfangyl Oct 11, 2024
2feb272
remove redundant debug console
songfangyl Oct 11, 2024
0757bca
Merge pull request #56 from CS3219-AY2425S1/question-filter
jingting1412 Oct 13, 2024
80c2235
Improve login ui
jingting1412 Oct 13, 2024
03797d4
Merge branch 'matching' of github.com:CS3219-AY2425S1/cs3219-ay2425s1…
Oct 14, 2024
107eecb
Add waiting page
jingting1412 Oct 14, 2024
5718edd
Choose category and difficulty
jingting1412 Oct 14, 2024
1424e32
Add mock timer
jingting1412 Oct 14, 2024
31f5948
Restructure matching logic of the matching queue
Oct 15, 2024
c5b9a06
Improve ui
jingting1412 Oct 16, 2024
6e32075
Add some TODO
jingting1412 Oct 16, 2024
9b9db26
Merge pull request #57 from CS3219-AY2425S1/ui-changes
jingting1412 Oct 16, 2024
65d9ae1
Manual test and debug
songfangyl Oct 18, 2024
d2489cd
Add difficulty and category as response
songfangyl Oct 18, 2024
f655609
Fetch categories from question service
songfangyl Oct 18, 2024
13c6067
Merge branch 'dev' into matching
songfangyl Oct 18, 2024
b4a4d72
add cancel match function
songfangyl Oct 19, 2024
aa177e7
remove console log
songfangyl Oct 19, 2024
dc35fed
Setup api gateway and calls to api gateway
LamJiuFong Oct 20, 2024
29ab083
change frontend folder name
LamJiuFong Oct 20, 2024
20feb67
Refactor code
songfangyl Oct 20, 2024
5044849
move const declaration to the top
songfangyl Oct 20, 2024
4afc822
Containerize matching service
songfangyl Oct 20, 2024
1a904c9
Fix call to question service bug
LamJiuFong Oct 20, 2024
dbc7bd1
Add context for authorization
LamJiuFong Oct 20, 2024
5473160
Add docker volumn
songfangyl Oct 20, 2024
6cab352
Merge pull request #62 from CS3219-AY2425S1/api-gateway-and-auth-context
songfangyl Oct 20, 2024
d6b3e0b
Merge branch 'dev' into matching
songfangyl Oct 20, 2024
173b617
Merge branch 'dev' into matching-frontend-integration
songfangyl Oct 20, 2024
a43bf3d
integrate matching service with frontend
songfangyl Oct 20, 2024
1d466a8
integrate cancel match in frontend
songfangyl Oct 20, 2024
6fae394
Limit to one category
songfangyl Oct 20, 2024
cabf947
remove user from queue when user disconnected
songfangyl Oct 20, 2024
b288148
Add confirmation dialog
songfangyl Oct 20, 2024
f9c0bba
Merge branch 'matching-frontend-integration' into matching
songfangyl Oct 20, 2024
2cfd736
containerize api gateway
songfangyl Oct 20, 2024
3e1d32f
Debug timeout message not shown correctly
songfangyl Oct 20, 2024
ed495f9
Add debug message to indicate current redis state
songfangyl Oct 20, 2024
8c98faf
Merge pull request #55 from CS3219-AY2425S1/matching
songfangyl Oct 21, 2024
5d768ed
Merge pull request #63 from CS3219-AY2425S1/dev
songfangyl Oct 21, 2024
ef7fbbe
create env.sample
lyuanww Oct 24, 2024
1f2ba69
Initialize collaboration service
songfangyl Oct 25, 2024
dd12590
Implement room service for collaboration
songfangyl Oct 25, 2024
956b93b
Improve debug message, only print if list is not empty
songfangyl Oct 25, 2024
86cd2a4
Create a room without any argument
songfangyl Oct 25, 2024
f258438
Implement room management
songfangyl Oct 25, 2024
0fca056
Add question category and difficulty to the room
songfangyl Oct 25, 2024
50c744c
Add frontend component: QuestionPanel
songfangyl Oct 25, 2024
51be416
Fix reloading issues by adding nginx.conf
jingting1412 Oct 26, 2024
6ff5a14
Add basic backend for chat
jingting1412 Oct 26, 2024
4ef040f
Setup basic communication fe+be
jingting1412 Oct 26, 2024
61defea
Update chat
jingting1412 Oct 26, 2024
cb8d053
Set up video calling
jingting1412 Oct 28, 2024
14d1536
Setup basic video call
jingting1412 Oct 28, 2024
9632f90
feat: code execution
lyuanww Oct 29, 2024
0a98e0b
Merge pull request #86 from CS3219-AY2425S1/liyuan/code-execution
lyuanww Oct 30, 2024
ca90bff
Merge branch 'collaboration-service' of https://github.com/CS3219-AY2…
jingting1412 Oct 30, 2024
ae7e583
Merge pull request #85 from CS3219-AY2425S1/collaboration-video
jingting1412 Oct 30, 2024
0ed6554
Add match acceptance logic
songfangyl Oct 30, 2024
13aaa9e
Merge branch 'collaboration-service' into match-accept
songfangyl Oct 30, 2024
66eb1b0
Merge pull request #82 from CS3219-AY2425S1/create-env.sample
LamJiuFong Oct 30, 2024
a90010f
fix bug
LamJiuFong Nov 1, 2024
dd02486
integrate matching service with collaboration service
LamJiuFong Nov 1, 2024
9a25469
Fetch question upon entering collaboration room
LamJiuFong Nov 2, 2024
ab60d0f
Fix button issue
jingting1412 Nov 2, 2024
9112e37
Update home page
jingting1412 Nov 2, 2024
6d7ec62
Update home page
jingting1412 Nov 2, 2024
f729a42
Improve signup page
jingting1412 Nov 2, 2024
e9b680b
Sync code
LamJiuFong Nov 2, 2024
3db471d
Uncomment room chat
LamJiuFong Nov 2, 2024
f0c6972
Enable broadcasting of messages in chatroom
LamJiuFong Nov 2, 2024
0a24b30
Fix error messages for login and signup page
jingting1412 Nov 2, 2024
e53e191
fix nginx refresh
lyuanww Nov 2, 2024
fb21a71
Update questions
jingting1412 Nov 2, 2024
b4c3216
Update question errors
jingting1412 Nov 2, 2024
e5a955f
Add button for navigation
jingting1412 Nov 2, 2024
237e60e
Update UI
jingting1412 Nov 2, 2024
2039c09
creat not found page and fix protected routes
lyuanww Nov 3, 2024
23b0e74
Merge pull request #94 from CS3219-AY2425S1/liyuan/fix-nginx-refresh
songfangyl Nov 3, 2024
14c7aeb
Merge dev branch, resolve conflict for frontend page reloading
songfangyl Nov 3, 2024
65bf6c7
Sorry, I missed a file that had a conflict.
songfangyl Nov 3, 2024
b7e1216
Sorry, I missed one more conflict
songfangyl Nov 3, 2024
860db94
Update docker compose
songfangyl Nov 3, 2024
05bf75a
Merge pull request #83 from CS3219-AY2425S1/collaboration-service
songfangyl Nov 3, 2024
82cf951
Add kubernetes yaml files for deployment
Nov 4, 2024
3e844bd
Add api gateway ymal file
songfangyl Nov 4, 2024
32252bb
Refactor code to take URL from environment
Nov 5, 2024
e6c19a8
Merge pull request #88 from CS3219-AY2425S1/ui-improvements
LamJiuFong Nov 5, 2024
d4fe60d
install nodemon in collaboration service
LamJiuFong Nov 5, 2024
b292e88
Add option to hide and show password at login/sign up page
LamJiuFong Nov 5, 2024
57d5f8f
resize question panel
LamJiuFong Nov 5, 2024
6a31286
Allow players to quit collab room and notify its partner
LamJiuFong Nov 5, 2024
404e920
Fix duplicate messages
jingting1412 Nov 5, 2024
fa0fd3f
style code editor
LamJiuFong Nov 5, 2024
7f949ab
Merge pull request #99 from CS3219-AY2425S1/room-improvements
LamJiuFong Nov 5, 2024
ba4708e
Merge branch 'dev' into bug-fixes
LamJiuFong Nov 5, 2024
23b2f80
Remove unused console logs and resolve warnings
LamJiuFong Nov 5, 2024
dc2bffe
Updated deployment files
Nov 5, 2024
63d8c25
fix chat duplication bug
LamJiuFong Nov 5, 2024
e1c340e
allow users to send message after pressing enter
LamJiuFong Nov 5, 2024
5c15662
Merge branch 'deployment' into api-gateway
songfangyl Nov 5, 2024
5ae3282
restore code and chat after refreshed
LamJiuFong Nov 5, 2024
0c073cc
add video call (draft)
LamJiuFong Nov 6, 2024
c9b7a44
fix socket and dns issue
Nov 6, 2024
b55d10c
Merge remote-tracking branch 'origin/bug-fixes' into deployment
Nov 6, 2024
9e85e85
fix non-matching port
Nov 6, 2024
7632eb8
Merge pull request #98 from CS3219-AY2425S1/bug-fixes
lyuanww Nov 6, 2024
4fd5e1d
fix
lyuanww Nov 6, 2024
bc9c1b8
Merge branch 'deployment' into api-gateway
songfangyl Nov 7, 2024
f48686e
Merge pull request #104 from CS3219-AY2425S1/liyuan/fix-protected-rou…
LamJiuFong Nov 7, 2024
f3c3201
Add button to navigate to login page at signup page
LamJiuFong Nov 7, 2024
19eb081
Style log out button and nav bar layout
LamJiuFong Nov 7, 2024
9681800
Hide match found message after user rejects a match
LamJiuFong Nov 7, 2024
818e8c8
Update logo and title of our app
LamJiuFong Nov 7, 2024
4b7783a
Remove comments
LamJiuFong Nov 9, 2024
2e2c178
Refactor collaboration room
LamJiuFong Nov 9, 2024
9aeddcf
Fix authentication bug
LamJiuFong Nov 9, 2024
97bddb7
Use Proxy for Api gateway
songfangyl Nov 9, 2024
359527a
Remove redundant code
songfangyl Nov 9, 2024
d8dfd0e
Merge branch 'dev' into api-gateway
songfangyl Nov 9, 2024
2d4429a
minor changes to deployment frontend
Nov 10, 2024
9455fc4
change to take lower diffuclty for matching in general queue
Nov 10, 2024
b797784
Merge pull request #108 from CS3219-AY2425S1/ui-improvements
songfangyl Nov 10, 2024
285b1f5
Merge branch 'dev' into deployment
songfangyl Nov 10, 2024
67e2053
Fix bug for protechted route
songfangyl Nov 10, 2024
c3de856
Put accepted party back in queue when match is rejected
Nov 10, 2024
3a47676
Remove videa call feature
songfangyl Nov 10, 2024
61b4c01
modify matching logic
Nov 10, 2024
d44bcf8
User account setting page
songfangyl Nov 10, 2024
cfe06fe
Integrate with backend
songfangyl Nov 10, 2024
bb9579a
Merge branch 'dev' into deployment
songfangyl Nov 10, 2024
69f2dda
Add signup email validation
jingting1412 Nov 10, 2024
ecf3838
Merge branch 'dev' of https://github.com/CS3219-AY2425S1/cs3219-ay242…
jingting1412 Nov 10, 2024
c4fb163
Add success message and prefile and debug
songfangyl Nov 10, 2024
6a1b504
Merge branch 'dev' into deployment
songfangyl Nov 10, 2024
01b1d4f
Merge pull request #110 from CS3219-AY2425S1/password-validaton
lyuanww Nov 10, 2024
d0f8c8b
reconfigure kubernetes setting
Nov 10, 2024
a29dfb2
Merge branch 'deployment' of github.com:CS3219-AY2425S1/cs3219-ay2425…
TehOPanas Nov 10, 2024
8ee587e
Resolve merge conflict
songfangyl Nov 10, 2024
3305156
Api gateway debug
songfangyl Nov 10, 2024
7e1e969
misc
Nov 10, 2024
de4efe9
Merge branch 'deployment' of github.com:CS3219-AY2425S1/cs3219-ay2425…
Nov 10, 2024
6d1b3c3
Add old password field
songfangyl Nov 11, 2024
0e8a38a
Store the user email in the useAuth
songfangyl Nov 11, 2024
60e8769
Password validation when changing password
songfangyl Nov 11, 2024
105ffee
Change back original package-lock
songfangyl Nov 11, 2024
447df3d
Merge branch 'user-service-changes' into deployment
songfangyl Nov 11, 2024
8a56318
Fix typo
songfangyl Nov 11, 2024
e4e62dd
Merge branch 'user-service-changes' into deployment
songfangyl Nov 11, 2024
63bc80a
fix partner randomly leaving
lyuanww Nov 11, 2024
d2e777c
Fix chat overflow
jingting1412 Nov 11, 2024
8b26d81
Revert "Fix chat overflow"
jingting1412 Nov 11, 2024
1187e77
Improve chat
jingting1412 Nov 11, 2024
2a550fd
leave room when close tab
lyuanww Nov 11, 2024
e5e3687
change message
lyuanww Nov 11, 2024
9b79e50
cleaning
lyuanww Nov 11, 2024
824b4f3
Merge branch 'dev' into liyuan/fix-partner-randomly-leaving-initally
lyuanww Nov 12, 2024
134c06d
feat: code editor sync
lyuanww Nov 12, 2024
93262b0
Merge branch 'dev' into matching
Nov 13, 2024
cf20051
Merge pull request #111 from CS3219-AY2425S1/user-service-changes
lyuanww Nov 13, 2024
c796446
Merge pull request #112 from CS3219-AY2425S1/liyuan/fix-partner-rando…
LamJiuFong Nov 13, 2024
78df400
Merge pull request #113 from CS3219-AY2425S1/liyuan/code-editor-sync
LamJiuFong Nov 13, 2024
64648d8
Merge branch 'deployment' into frontend-configuration
songfangyl Nov 13, 2024
4dff49f
modify matching backend logic
Nov 13, 2024
bc7901a
Configure frontend api link into env file
songfangyl Nov 13, 2024
6aa064a
Fix docker compose file for code execution service
songfangyl Nov 13, 2024
4114192
Clean up the code for api gateway
songfangyl Nov 13, 2024
693e04f
Merge pull request #115 from CS3219-AY2425S1/frontend-configuration
songfangyl Nov 13, 2024
cf27c46
Implemented match reject and requeue
Nov 13, 2024
979a6a4
small fixes
lyuanww Nov 13, 2024
fb4b14d
small fix
lyuanww Nov 13, 2024
da0509f
Merge pull request #116 from CS3219-AY2425S1/liyuan/fix
lyuanww Nov 13, 2024
dcedf71
Resolve conflict
Nov 13, 2024
e6f1615
Integrate match reject with frontend
Nov 13, 2024
04934d2
Merge branch 'matching' into dev
Nov 13, 2024
4c3d7e1
Change output message when timeout on accepting match
Nov 13, 2024
7f90305
Merge branch 'dev'
Nov 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Node modules (both backend and frontend)
**/node_modules

# Logs
**/npm-debug.log*
**/yarn-debug.log*

# Environment variables
**/.env
**/.env.local
**/.env.development.local
**/.env.test.local
**/.env.production.local

# Build directory (React frontend)
**/build/
**/dist/

# Coverage directory
**/coverage/

# Optional npm cache directory
**/.npm

# Optional yarn cache directory
**/.yarn/

# VS Code settings
**/.vscode/

# Jetbrain
**/.idea

# macOS
**/.DS_Store

# Windows
**/Thumbs.db
28 changes: 23 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
# CS3219 Project (PeerPrep) - AY2425S1
## Group: Gxx

### Note:
- You can choose to develop individual microservices within separate folders within this repository **OR** use individual repositories (all public) for each microservice.
- In the latter scenario, you should enable sub-modules on this GitHub classroom repository to manage the development/deployment **AND** add your mentor to the individual repositories as a collaborator.
- The teaching team should be given access to the repositories as we may require viewing the history of the repository in case of any disputes or disagreements.
## Group: G12

### How to Run the Project

Follow the steps below to set up and run the project using Docker Compose.

### Prerequisites

Make sure Docker and Docker Compose are installed on your machine.

#### Installing Docker

If you haven't installed Docker yet, follow the instructions for your operating system:

- **Windows / macOS**: Download Docker Desktop from [here](https://www.docker.com/products/docker-desktop) and install it.
- **Linux**: Follow the instructions [here](https://docs.docker.com/engine/install/).

### Build and start docker container

Run these command at the root directory:

1. `docker-compose build`
2. `docker-compose up`
1 change: 1 addition & 0 deletions api-gateway/.env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PORT=
13 changes: 13 additions & 0 deletions api-gateway/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM node:20-alpine

WORKDIR /app

COPY package*.json ./

RUN npm install

COPY . .

EXPOSE 3003

CMD ["npm", "start"]
46 changes: 46 additions & 0 deletions api-gateway/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import express from "express";
import "dotenv/config";
import { userProxy } from "./proxy/userProxy.js";
import { questionProxy } from "./proxy/questionProxy.js";
import { verifyAccessToken } from "./middleware/authentication.js";
import cors from "cors";
import { authRouter } from "./router/authRouter.js";
import { codeExecutionProxy } from "./proxy/codeExecutionProxy.js";

export const QUESTION_SERVICE =
process.env.QUESTION_SERVICE_URL || "http://localhost:3002";

export const app = express();

app.use(cors());
app.use(express.json());

// To handle CORS Errors
app.use((req, res, next) => {
res.header("Access-Control-Allow-Origin", "*");

res.header(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept, Authorization"
);

// Browsers usually send this before PUT or POST Requests
if (req.method === "OPTIONS") {
res.header(
"Access-Control-Allow-Methods",
"GET, POST, DELETE, PUT, PATCH"
);
return res.status(200).json({});
}

next();
});

app.use("/auth", authRouter);
app.use("/question", verifyAccessToken, questionProxy);
app.use("/user", userProxy)
app.use("/code-execution", verifyAccessToken, codeExecutionProxy)

app.listen(3210, () => {
console.log("Backend listening on port 3003");
});
38 changes: 38 additions & 0 deletions api-gateway/middleware/authentication.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import axios from 'axios';
import { USER_SERVICE } from '../proxy/userProxy.js';

export async function verifyAccessToken(req, res, next) {
try {
console.log('Verify: Request headers:', req.headers);

// Save the original headers and body
const originalHeaders = { ...req.headers };
const originalBody = req.body;

// Modify headers specifically for this request
const headers = { ...originalHeaders, 'Content-Length': '0' };

// Perform the GET request with modified headers
const response = await axios.get(`${USER_SERVICE}/auth/verify-token`, {
headers: headers
});

// Restore the original headers and body for the next middleware
req.headers = originalHeaders;
req.body = originalBody;

// Attach user data to req for the next middleware
req.user = response.data;

console.log('Authentication successful:', {
userId: response.data?.id,
method: req.method,
path: req.path
});

next();
} catch(err) {
console.error("API Gateway -> Error verifying access token ", err.response?.data || err.message);
res.status(403).json({ message: "Invalid user"});
}
}
Loading