Skip to content

Commit

Permalink
Merge pull request #42 from CS3219-AY2425S1/y-websocket-server
Browse files Browse the repository at this point in the history
add server backend
  • Loading branch information
sp4ce-cowboy authored Nov 2, 2024
2 parents f7a61b8 + 3b0d9bc commit f9b86a3
Show file tree
Hide file tree
Showing 8 changed files with 1,735 additions and 1 deletion.
6 changes: 6 additions & 0 deletions peerprep/backend/collab-service/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DB_CLOUD_URI=mongodb+srv://default:yN2zzXYyZz9CTwsB@peerprep-collab-service.c0em2.mongodb.net/
DB_LOCAL_URI=mongodb://127.0.0.1:27017/peerprepCollabServiceDB
PORT=1234

# Will use cloud MongoDB Atlas database
ENV=PROD
8 changes: 8 additions & 0 deletions peerprep/backend/collab-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM node:22-alpine

COPY package.json package-lock.json ./
RUN npm install

COPY . .

CMD ["npm", "start"]
22 changes: 22 additions & 0 deletions peerprep/backend/collab-service/config/db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const mongoose = require('mongoose');
const dotenv = require('dotenv');

dotenv.config();

const connectDB = async () => {
try {
const uri = process.env.ENV === 'PROD' ? process.env.DB_CLOUD_URI : process.env.DB_LOCAL_URI;

if (!uri) {
throw new Error("MongoDB URI is not defined in environment variables");
}

await mongoose.connect(uri);
console.log("MongoDB Connected!");
} catch (error) {
console.error(`Error connecting to MongoDB: ${error.message}`);
process.exit(1);
}
};

module.exports = connectDB;
Loading

0 comments on commit f9b86a3

Please sign in to comment.