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

N1 Nice to Have #52

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
190 changes: 190 additions & 0 deletions peerprep/backend/collab-service/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions peerprep/backend/collab-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
"express": "^4.21.1",
"mongoose": "^8.7.3",
"node-static": "^0.7.11",
"socket.io": "^4.8.1",
"cors": "^2.8.5",
"nodemon": "^2.0.15",
"ws": "^7.4.2",
"y-websocket": "^1.3.9",
"yjs": "^13.4.12"
Expand Down
30 changes: 28 additions & 2 deletions peerprep/backend/collab-service/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ const setupWSConnection = ywsUtils.setupWSConnection;
const docs = ywsUtils.docs;
const connectDB = require('../config/db');
const { storeDocument, getDocument } = require('./controller/collab-controller');
const { Server } = require("socket.io");
const cors = require("cors");

const app = express();
const server = http.createServer(app);
const wss = new WebSocket.Server({ server });

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

// Connect to MongoDB
Expand Down Expand Up @@ -49,7 +52,30 @@ wss.on('connection', (conn, req) => {
setupWSConnection(conn, req, { gc: req.url.slice(1) !== 'ws/prosemirror-versions' });
});

const io = new Server(server, {
cors: {
origin: "http://localhost:5173", // Adjust this to match your frontend URL
methods: ["GET", "POST"],
},
});

io.on("connection", (socket) => {
console.log(`User Connected: ${socket.id}`);

socket.on("join_room", (data) => {
socket.join(data);
});

socket.on("send_message", (data) => {
socket.in(data.room).emit("receive_message", data); // Send to all clients except sender
});

socket.on("disconnect", () => {
console.log(`User Disconnected: ${socket.id}`);
});
});

const PORT = process.env.PORT || 1234;
server.listen(PORT, () => {
console.log(`Server is running at http://localhost:1234`);
});
console.log(`Server is running at http://localhost:${PORT}`);
});
9 changes: 0 additions & 9 deletions peerprep/backend/user-service/.env.sample

This file was deleted.

5 changes: 5 additions & 0 deletions peerprep/frontend/.env.development
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
VITE_AUTH_API_URL=http://localhost:3001/auth
VITE_USER_API_URL=http://localhost:3001/users
VITE_MATCH_API_URL=http://localhost:3000/matchingrequest
VITE_QUESTION_API_URL=http://localhost:8080/api/questions
VITE_WEBSOCKET_API_URL=ws://localhost:1234/
5 changes: 5 additions & 0 deletions peerprep/frontend/.env.production
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
VITE_AUTH_API_URL=http://34.71.236.157:3001/auth
VITE_USER_API_URL=http://34.71.236.157:3001/users
VITE_MATCH_API_URL=http://34.71.236.157:3000/matchingrequest
VITE_QUESTION_API_URL=http://34.71.236.157:8080/api/questions
VITE_WEBSOCKET_API_URL=ws://34.71.236.157:1234/
5 changes: 5 additions & 0 deletions peerprep/frontend/.firebaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"projects": {
"default": "main-440905"
}
}
16 changes: 16 additions & 0 deletions peerprep/frontend/firebase.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"hosting": {
"public": "dist",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
}
30 changes: 15 additions & 15 deletions peerprep/frontend/src/api/assescodeApi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import axios, { AxiosError } from 'axios';
import axios from 'axios';

const API_URL = 'http://localhost:8080/api/gpt/asses';

Expand All @@ -10,20 +10,20 @@ export class ApiError extends Error {
}
}

const handleApiError = (error: unknown): never => {
if (axios.isAxiosError(error)) {
const axiosError = error as AxiosError;
if (axiosError.response) {
throw new ApiError(`API error: ${axiosError.response.statusText}`, axiosError.response.status);
} else if (axiosError.request) {
throw new ApiError('API error: No response received from the server');
} else {
throw new ApiError(`API error: ${axiosError.message}`);
}
} else {
throw new ApiError(`API error: An unexpected error occurred ${error}`);
}
};
// const handleApiError = (error: unknown): never => {
// if (axios.isAxiosError(error)) {
// const axiosError = error as AxiosError;
// if (axiosError.response) {
// throw new ApiError(`API error: ${axiosError.response.statusText}`, axiosError.response.status);
// } else if (axiosError.request) {
// throw new ApiError('API error: No response received from the server');
// } else {
// throw new ApiError(`API error: ${axiosError.message}`);
// }
// } else {
// throw new ApiError(`API error: An unexpected error occurred ${error}`);
// }
// };

export const assesCode = async (currentCode: string): Promise<string> => {
try {
Expand Down
Loading
Loading