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 313 commits into
base: feedback
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
313 commits
Select commit Hold shift + click to select a range
17f2aed
Fix get user request
ChillinRage Sep 28, 2024
e676199
Edit error handling to display correct error message
inezkok Sep 29, 2024
b51064a
Fix edit question bug of not changing title
inezkok Sep 29, 2024
db9fae8
Fix warnings in console
inezkok Sep 29, 2024
3c235f1
Merge pull request #7 from CS3219-AY2425S1/user-be
inezkok Sep 29, 2024
099931e
Add placeholder profile page
Chen1x Sep 29, 2024
ab4e0be
Merge pull request #14 from CS3219-AY2425S1/m2-questions-images
Chen1x Sep 29, 2024
c6caf97
Resolve merge conflict with main
Chen1x Sep 29, 2024
7d98871
Merge pull request #15 from CS3219-AY2425S1/user-fe
inezkok Sep 29, 2024
9c7d46d
Fix question controller validity check and existing title check bugs
inezkok Sep 29, 2024
118a32c
Merge pull request #20 from CS3219-AY2425S1/question-be
ChillinRage Sep 29, 2024
bfe2933
Remove user service
ChillinRage Sep 29, 2024
889da39
Remove Home page, disable all buttons on Navbar, and rename to Questi…
Chen1x Sep 29, 2024
2a23b21
Change tab icon and tab name
Chen1x Sep 29, 2024
d7c4ce4
Adding length constraints
jannnice Sep 29, 2024
0500a14
Fix error handling on frontend
inezkok Sep 30, 2024
b52f866
Display length constraints on frontend
inezkok Sep 30, 2024
8fee2b0
Fix topic array bug
inezkok Sep 30, 2024
d3988ed
Merge pull request #21 from CS3219-AY2425S1/delete-user
inezkok Sep 30, 2024
324a92e
Recover user service
ChillinRage Sep 30, 2024
338888d
Implement hook to verify user's authentication status
miljyy Sep 30, 2024
fcf3e54
Organise files into folders
miljyy Sep 30, 2024
a8bf49e
Standardise folder name
inezkok Oct 1, 2024
8233189
Containerize question service (backend)
inezkok Oct 1, 2024
042aa85
Update README to include instructions for containerization
inezkok Oct 1, 2024
a58a76a
Implement multiselect for question topics
miljyy Oct 1, 2024
21e0aa0
Modify colour of difficulty depending on value
miljyy Oct 1, 2024
f4062e6
Adjust questions header to be aligned with question table
miljyy Oct 1, 2024
d4b02f3
Add authentication for CRUD question service
inezkok Oct 2, 2024
42c12de
Modify auth and initial landing page
miljyy Oct 2, 2024
2b76e43
Merge pull request #23 from CS3219-AY2425S1/m2-questions-fe-miljyy
inezkok Oct 2, 2024
933c90c
Merge branch 'main' into question-be
inezkok Oct 2, 2024
e6d31b3
Develop frontend for home page
miljyy Oct 2, 2024
48d5228
Edit frontend service calls
inezkok Oct 2, 2024
cfc9c49
Add authentication to question service
ChillinRage Oct 2, 2024
0227238
Add refresh button to question table
ChillinRage Oct 2, 2024
90cefa2
Change render behavior for Add button
ChillinRage Oct 2, 2024
72e3ba6
Change render behavior for Edit and Delete button
ChillinRage Oct 2, 2024
fc17fc1
Install axios dependency
inezkok Oct 3, 2024
8f812e9
Update README to include authentication headers for CRUD
inezkok Oct 3, 2024
ef5c2b6
change file structure
ChillinRage Oct 3, 2024
97283b0
Containerize user service back end
ChillinRage Oct 3, 2024
16f3c21
Update .dockerignore
ChillinRage Oct 3, 2024
65ea170
Merge pull request #25 from CS3219-AY2425S1/refresh-question-btn
inezkok Oct 5, 2024
5d71cbe
Merge pull request #24 from CS3219-AY2425S1/m2-questions-fe-miljyy
inezkok Oct 5, 2024
470a97b
Resolve merge conflict with main
inezkok Oct 5, 2024
017e707
Merge pull request #22 from CS3219-AY2425S1/question-be
ChillinRage Oct 5, 2024
b4c0312
front end containerisation
jannnice Oct 5, 2024
ce14198
Minor updates
jannnice Oct 5, 2024
9485b10
Merge branch 'main' into user-fe-profile
Chen1x Oct 5, 2024
c64e583
Containerize user be and folder restructure
ChillinRage Oct 5, 2024
a71f1ff
Fix QuestionTable regression and update import statement
Chen1x Oct 5, 2024
def7d2c
Typo fixes
jannnice Oct 6, 2024
783db16
Merge pull request #27 from CS3219-AY2425S1/jannnice-fe
inezkok Oct 6, 2024
dc93a22
Minor bug fix
ChillinRage Oct 6, 2024
edf07f6
Merge branch 'main' into user-backend
ChillinRage Oct 6, 2024
249ec28
Update docker-compose.yaml
ChillinRage Oct 6, 2024
e23ba78
Add edit info function for profile page
Chen1x Oct 6, 2024
5797ce8
Merge pull request #28 from CS3219-AY2425S1/user-backend
inezkok Oct 6, 2024
f8bb1e6
Separate .env files based on local or docker environment
inezkok Oct 6, 2024
b8d1295
Update question backend README for local development
inezkok Oct 6, 2024
ef8b019
Merge pull request #29 from CS3219-AY2425S1/m3-containerization
ChillinRage Oct 6, 2024
97457dd
Add upload and remove photo function
Chen1x Oct 6, 2024
788c8da
Fix aesthetics of profile pic bubble-option
Chen1x Oct 6, 2024
e9da050
Remove change password button
Chen1x Oct 6, 2024
3eb3a35
Update profile image route
ChillinRage Oct 6, 2024
9cfb74a
Merge remote-tracking branch 'origin/user-backend' into user-fe-profile
Chen1x Oct 7, 2024
d2fa093
Add function to edit/remove profile photo
Chen1x Oct 7, 2024
3628354
Merge branch 'main' into user-fe-profile
Chen1x Oct 7, 2024
640cce6
update user backend to match front end
ChillinRage Oct 8, 2024
fdeb1c9
Refactor multer in user backend
ChillinRage Oct 10, 2024
2b2dd9e
Update Dockerfile
ChillinRage Oct 10, 2024
6875235
Merge pull request #30 from CS3219-AY2425S1/user-fe-profile
miljyy Oct 13, 2024
42ba82d
Merge pull request #33 from CS3219-AY2425S1/main
ChillinRage Oct 13, 2024
e55d4fa
Add validation to user service
ChillinRage Oct 13, 2024
413e58e
basic RabbitMQ skeleton
jannnice Oct 16, 2024
00f9664
dynamic matching system
jannnice Oct 17, 2024
5933f10
front end button to add to queue
jannnice Oct 17, 2024
f321704
Include username in the queue
jannnice Oct 17, 2024
75e6615
match timer popup
jannnice Oct 17, 2024
effc6da
matching logic
jannnice Oct 17, 2024
084e0e6
matching logic part 2
jannnice Oct 17, 2024
01bda18
fixing rabbitmq connection
jannnice Oct 18, 2024
cffa3e5
typo
jannnice Oct 18, 2024
03ec386
cancel users from the queue
jannnice Oct 19, 2024
55342c2
Success Match Popup message
jannnice Oct 19, 2024
7e3a07c
log messages
jannnice Oct 19, 2024
b1aafb1
cancel button
jannnice Oct 19, 2024
d2d0a93
Fix missing line
ChillinRage Oct 19, 2024
cb7578d
complete pop ups
jannnice Oct 19, 2024
6e0e8fd
including pair name in popup
jannnice Oct 19, 2024
361cbb7
fixed mismatching and off-ed backend countdown when matched
jannnice Oct 19, 2024
b9c82de
Merge pull request #35 from CS3219-AY2425S1/matching-service
inezkok Oct 20, 2024
2b341a8
centralise popup
jannnice Oct 20, 2024
daae9c0
Merge pull request #36 from CS3219-AY2425S1/matching-service
inezkok Oct 20, 2024
61ae355
Add basic OTP implementation for Sign up process
Chen1x Oct 25, 2024
87f6334
Add basic implementation of Forgot password functionalities
Chen1x Oct 25, 2024
f494173
Add email verification to account creation
ChillinRage Oct 26, 2024
c00c138
Update user formatting
ChillinRage Oct 26, 2024
1a7fb84
Resend verification
ChillinRage Oct 26, 2024
9fc0e14
Update verify email page
ChillinRage Oct 26, 2024
d6aba5b
Refactor code
ChillinRage Oct 26, 2024
7897217
Implement frontend of code editor
miljyy Oct 26, 2024
204de56
Develop simple code editor
miljyy Oct 27, 2024
217daa2
Implement collaborative code editor
inezkok Oct 29, 2024
29d9be9
Add icon to collab nav bar
inezkok Oct 29, 2024
edf67ad
Remove node_modules from git tracking
inezkok Oct 29, 2024
6dffc5c
Try to implement quitting logic for collab service
inezkok Oct 29, 2024
b7f6fbc
Implement grace period for user reconnection and fix socket room bug
inezkok Oct 30, 2024
0cb415e
Implement question retrieval on match
miljyy Oct 30, 2024
19d1827
Merge branch 'collab-service' into collab-service-jy
miljyy Oct 30, 2024
b636759
Add verification to email updates
ChillinRage Oct 30, 2024
04428df
Fix email update bugs
ChillinRage Oct 30, 2024
3544842
Fix issues for question retrieval, display and roomId creation
miljyy Oct 30, 2024
b41ac06
Merge branch 'collab-service-jy' of https://github.com/CS3219-AY2425S…
miljyy Oct 30, 2024
5d7639e
Fix error in code
miljyy Oct 30, 2024
0a0db27
created timer + pop up message when session timer is up
jannnice Oct 30, 2024
ebffb99
changed time format to MM:SS
jannnice Oct 30, 2024
8ca01c0
Merge branch 'collab-service' into collab-service-jannice
miljyy Oct 30, 2024
fa10240
Merge pull request #38 from CS3219-AY2425S1/collab-service-jy
inezkok Oct 30, 2024
685c788
Merge branch 'collab-service' into collab-service-jannice
jannnice Oct 31, 2024
c6b48de
Fix merge errors
inezkok Oct 31, 2024
964f89d
Add email verification and validation
ChillinRage Oct 31, 2024
ec6f884
Add email and password update verification
ChillinRage Oct 31, 2024
a2008aa
Implement user history
ChillinRage Oct 31, 2024
3f62035
Add question history table to profile
ChillinRage Oct 31, 2024
4c32bc9
Move history table to history page
ChillinRage Oct 31, 2024
bc9bc09
Revert "Move history table to history page"
ChillinRage Nov 2, 2024
d5d6fe0
Revert "Add question history table to profile"
ChillinRage Nov 2, 2024
ba6e290
Fix typo
ChillinRage Nov 2, 2024
afee8a7
Add routes for get user by username
ChillinRage Nov 2, 2024
0628eb8
Merge branch 'user-backend' into question-history
ChillinRage Nov 2, 2024
a6072be
Create history page
ChillinRage Nov 2, 2024
d857c08
Update auth-controller.js
ChillinRage Nov 2, 2024
7ef243d
Merge branch 'user-backend' into question-history
ChillinRage Nov 2, 2024
c898186
split logic
jannnice Nov 2, 2024
9520305
Merge branch 'collab-service' into question-history
ChillinRage Nov 2, 2024
cd210eb
Update controller-utils.js
ChillinRage Nov 2, 2024
4ffbfc5
Merge branch 'user-backend' into question-history
ChillinRage Nov 2, 2024
83d1472
timer synced + countdown for users to make decision
jannnice Nov 2, 2024
5cc237b
Create history model and update user backend
ChillinRage Nov 2, 2024
a1fbeef
extend session flow
jannnice Nov 2, 2024
1ba82a3
Merge pull request #39 from CS3219-AY2425S1/collab-service-jannice
inezkok Nov 2, 2024
9def7d5
Add route for multiple gets
ChillinRage Nov 2, 2024
244e08b
Separate question in collab into component
inezkok Nov 2, 2024
b15b85a
Add request from fe to be
ChillinRage Nov 2, 2024
0541b3f
minor fix
ChillinRage Nov 2, 2024
6ae7430
Add dialog for question and solution
ChillinRage Nov 3, 2024
3aa9d33
Improve datetime display
ChillinRage Nov 3, 2024
d26772b
generate unique roomId
jannnice Nov 4, 2024
4fd61bf
Merge branch 'collab-service' into question-history
ChillinRage Nov 4, 2024
a4ed8aa
Fix ResizeObserver loop error
miljyy Nov 4, 2024
7df8e9e
Minor bug fixes
miljyy Nov 4, 2024
c1212f8
Modify question retrieval logic
miljyy Nov 4, 2024
d07b17f
Modify frontend on collab page to match mockup
miljyy Nov 4, 2024
8fd93f7
fix roomId flow
jannnice Nov 4, 2024
c2e3d8a
fix countdown syncing
jannnice Nov 4, 2024
204900a
notification popup for when session is started
jannnice Nov 4, 2024
774d92a
Fix question retrieval logic to use roomId
inezkok Nov 5, 2024
b8ab54e
Add back check for non-existent question
inezkok Nov 5, 2024
06081bb
develop frontend for running code
miljyy Nov 5, 2024
94796ba
Merge pull request #37 from CS3219-AY2425S1/collab-service
miljyy Nov 5, 2024
12109c6
Merge branch 'main' of https://github.com/CS3219-AY2425S1/cs3219-ay24…
miljyy Nov 5, 2024
83013cb
Implement simple code execution
miljyy Nov 5, 2024
cb72ff4
Modify frontend for collab page
miljyy Nov 5, 2024
9f946fb
Merge branch 'main' into question-history
ChillinRage Nov 5, 2024
e974c15
Merge branch 'user-be' into user-fe
ChillinRage Nov 5, 2024
adec18b
Merge branch 'email_pw_validation' into user-fe
ChillinRage Nov 5, 2024
c484d1c
Update email verification to match backend
ChillinRage Nov 5, 2024
e341dd9
manager partner quit popup
jannnice Nov 5, 2024
c06db3a
popup for timeout for making decision
jannnice Nov 5, 2024
8201326
Update for password change
ChillinRage Nov 5, 2024
fb09ab5
Merge branch 'main' into user-fe
ChillinRage Nov 5, 2024
e482f81
auto redirect to collab once matched
jannnice Nov 6, 2024
744a700
Add text chat functionalities
Chen1x Nov 6, 2024
5370474
Merge branch 'collab-service' into collab-service-jannice
jannnice Nov 6, 2024
19e3fb9
typo fix
jannnice Nov 6, 2024
20f67de
Merge pull request #42 from CS3219-AY2425S1/collab-service-jannice
inezkok Nov 6, 2024
182075e
Merge branch 'main' into code-execution
inezkok Nov 6, 2024
dcee968
Fix import error
inezkok Nov 6, 2024
366e506
Replace input and expected output into examples in question
inezkok Nov 6, 2024
b082c59
Add styling to text messages
Chen1x Nov 6, 2024
39dc244
Merge branch 'main' into text-chat
Chen1x Nov 6, 2024
9799a48
Improved asthetics of text field
Chen1x Nov 6, 2024
e1d5918
Fix image fetching
ChillinRage Nov 7, 2024
723d330
Merge branch 'text-chat' into code-execution
inezkok Nov 7, 2024
2ef0213
Merge pull request #44 from CS3219-AY2425S1/ChillinRage-patch-2
miljyy Nov 7, 2024
179d69f
Create tabs for output and chatbox
inezkok Nov 7, 2024
3874694
Add history update to front end
ChillinRage Nov 7, 2024
5bd1d95
Change output style
inezkok Nov 7, 2024
e845850
Merge branch 'main' into question-history
ChillinRage Nov 7, 2024
e7c71a5
Merge branch 'main' into question-history
ChillinRage Nov 7, 2024
1c66a5e
Merge branch 'main' into question-history
ChillinRage Nov 7, 2024
12a271c
Update MatchFound.js
ChillinRage Nov 7, 2024
8e4339d
Merge branch 'question-history' of https://github.com/CS3219-AY2425S1…
ChillinRage Nov 7, 2024
2aec9c8
Update status on submit
ChillinRage Nov 7, 2024
4edeb3c
Update variable from useState to useRef
ChillinRage Nov 7, 2024
61ad748
Fix disappearing chat problem
Chen1x Nov 7, 2024
aefe2f1
Add more custom code editor themes
inezkok Nov 7, 2024
7401994
Merge branch 'main' into code-execution
inezkok Nov 7, 2024
4fd02dd
Merge pull request #40 from CS3219-AY2425S1/question-history
inezkok Nov 8, 2024
628dc9e
Merge branch 'main' into code-execution
inezkok Nov 8, 2024
4d833e5
Add history support for multiple languages
ChillinRage Nov 8, 2024
56a3f47
Fix code editor and execution language issue
inezkok Nov 8, 2024
718cf31
Merge pull request #43 from CS3219-AY2425S1/code-execution
miljyy Nov 8, 2024
32ad1ad
Add functionality to submit button
ChillinRage Nov 8, 2024
5cd6f22
Merge pull request #45 from CS3219-AY2425S1/question-history
inezkok Nov 8, 2024
dcafc6f
basic setup for chatbot + response reflected
jannnice Nov 8, 2024
9e4bb80
reflect users messages
jannnice Nov 8, 2024
44db414
Merge branch 'main' into user-fe
ChillinRage Nov 8, 2024
94ef455
Minor refactor to user service
ChillinRage Nov 8, 2024
f2f9afe
Add mic button
Chen1x Nov 8, 2024
df75c34
Place the mic within chatbox
Chen1x Nov 8, 2024
c876e7b
Add fully working mic button
Chen1x Nov 8, 2024
5e01d87
Add mute button
Chen1x Nov 8, 2024
a8b2740
Fix errors
ChillinRage Nov 10, 2024
d92f7db
Update question service backend for code execution
inezkok Nov 10, 2024
b48dc31
Try editing create question form (still contains error)
inezkok Nov 10, 2024
124d0b1
PR initiation
jannnice Nov 10, 2024
08e6fdc
Add env file for collab service and frontend
inezkok Nov 12, 2024
3d2428e
Add .env into .gitignore
inezkok Nov 12, 2024
607d603
Fix create and edit question errors from new question schema
inezkok Nov 12, 2024
7e4e5b4
Shorten updateQuestion
inezkok Nov 12, 2024
b823476
Fix sign up
ChillinRage Nov 12, 2024
91af126
Improve update message
ChillinRage Nov 12, 2024
1134687
Merge pull request #41 from CS3219-AY2425S1/user-fe
inezkok Nov 12, 2024
bf9fa3d
Try implementing loading of default code (now it appears twice)
inezkok Nov 13, 2024
9d9b89c
Fix double default code
Chen1x Nov 13, 2024
73b1d55
Clear editor after room is empty left
inezkok Nov 13, 2024
01b74c1
Fix duplicate code when joining repeatedly
Chen1x Nov 13, 2024
28864c7
Add reset code button
inezkok Nov 13, 2024
04780ad
Add in function_name field for question schema
inezkok Nov 13, 2024
81ace4f
Implement running test cases (python and javascript)
inezkok Nov 13, 2024
6f3c1b7
Fix height issue of test cases and disable java testcase
inezkok Nov 13, 2024
c070076
Merge pull request #48 from CS3219-AY2425S1/voice-chat
inezkok Nov 13, 2024
5e9818c
Update readme.md
miljyy Nov 13, 2024
bf971d6
Merge branch 'main' into code-execution
inezkok Nov 13, 2024
4046f63
Merge branch 'main' into generative-ai
inezkok Nov 13, 2024
42f82f9
Fix errors from merge
inezkok Nov 13, 2024
5fe0aeb
Fix styling inconsistency for tabs
inezkok Nov 13, 2024
8ee9f7c
frontend filter tabs
jannnice Nov 13, 2024
3e15136
topics filter dropdown
jannnice Nov 13, 2024
7692cad
Merge pull request #47 from CS3219-AY2425S1/generative-ai
inezkok Nov 14, 2024
434cd34
Merge branch 'main' into code-execution
inezkok Nov 14, 2024
e4a0fff
Edit to handle single quote and double quote
inezkok Nov 14, 2024
aa0591e
Merge pull request #49 from CS3219-AY2425S1/code-execution
miljyy Nov 14, 2024
713805b
Merge pull request #51 from CS3219-AY2425S1/readme
inezkok Nov 14, 2024
ab2b62d
Merge branch 'main' into question-service-enhancements
inezkok Nov 14, 2024
55eceaa
Implement filtering for question based on both topic and difficulty
inezkok Nov 14, 2024
26662cb
Merge pull request #50 from CS3219-AY2425S1/question-service-enhancem…
Chen1x 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
backend/question-backend/.env.local
40 changes: 35 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,37 @@
[![Review Assignment Due Date](https://classroom.github.com/assets/deadline-readme-button-22041afd0340ce965d47ae6ef1cefeee28c7c493a6346c4f15d667ab976d596c.svg)](https://classroom.github.com/a/bzPrOe11)

# 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: G34
PeerPrep is a web application aimed to help students prepare for technical whiteboard interviews through peer-to-peer practice in a collaborative space.

## Table of Contents
- [Table of Contents](#table-of-contents)
- [Architecture Overview](#architecture-overview)
- [Project Setup](#project-setup)
- [Prerequisites](#prerequisites)
- [Instructions](#instructions)

## Architecture Overview
PeerPrep's architecture combines a scalable, microservices-based backend with a monolithic frontend, allowing for flexible backend operations and simpler frontend maintenance. Its backend is developed with Node.js and Express, while the frontend is built using React.js.

<img src='./frontend/src/assets/architecture.PNG'>

## Project Setup

In this section, you will set up PeerPrep to run locally.

### Prerequisites
1. [Docker](https://docs.docker.com/get-docker/) installed on your machine
2. [docker-compose](https://docs.docker.com/compose/install/) installed

### Instructions
1. Clone this repository into your local machine.
2. Configure `.env` files as required.
3. Navigate to the root directory of this repository (where `docker-compose.yaml` is located).
4. Run `docker-compose` to build and run all the services.

``` bash
docker-compose up --build
```
5. Once started, open up your browser and go to http://localhost:3000/ to access PeerPrep.
2 changes: 2 additions & 0 deletions backend/collab-backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
npm-debug.log
4 changes: 4 additions & 0 deletions backend/collab-backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/node_modules

.DS_Store
.env
13 changes: 13 additions & 0 deletions backend/collab-backend/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 8200 8201

CMD ["npm", "start"]
89 changes: 89 additions & 0 deletions backend/collab-backend/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
require('dotenv').config();
const { OpenAI } = require('openai');

const express = require('express');
const cors = require('cors');
const dotenv = require('dotenv');
const { createServer } = require('http');
const { Server } = require('socket.io');
const WebSocket = require('ws');
const setupWSConnection = require('y-websocket/bin/utils').setupWSConnection;
const handleSocketEvents = require('./socketHandlers');

dotenv.config();

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

// Port configurations
const { SOCKET_IO_PORT, YJS_PORT } = process.env;

// Initialize OpenAI client
const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY, // Ensure your API key is set in .env
});

// Example: Defining a POST route at /chat
app.post('/chat', async (req, res) => {
const { message } = req.body;

if (!message) {
return res.status(400).json({ error: 'Message is required' });
}

try {
const response = await openai.chat.completions.create({
model: 'gpt-3.5-turbo', // Adjust model name if necessary
messages: [{ role: 'user', content: message }],
});

const chatbotReply = response.choices[0].message.content;
res.json({ reply: chatbotReply });

} catch (error) {
console.error('OpenAI API Error:', error); // Log the error details

// Respond with a more detailed error message if needed
res.status(500).json({
error: 'An error occurred while processing your request',
details: error.message // Include error details for more insight
});
}
});

// Server setup for Socket.IO
const ioServer = createServer(app);
const io = new Server(ioServer, {
path: "/socket.io",
cors: { origin: 'http://localhost:3000' },
});

handleSocketEvents(io);

ioServer.listen(SOCKET_IO_PORT, () => {
console.log(`Socket.IO server listening at http://localhost:${SOCKET_IO_PORT}`);
});

// Server setup for y-websocket
const yjsServer = createServer(app);
const wss = new WebSocket.Server({ noServer: true });

yjsServer.on('upgrade', (request, socket, head) => {
if (request.url.startsWith('/yjs')) {
wss.handleUpgrade(request, socket, head, (ws) => {
wss.emit('connection', ws, request);
});
} else {
socket.destroy();
}
});

wss.on('connection', (ws, req) => {
console.log("WebSocket client connected for y-websocket");
setupWSConnection(ws, req);
});

yjsServer.listen(YJS_PORT, () => {
console.log(`y-websocket server listening at http://localhost:${YJS_PORT}`);
});
Loading