Skip to content

Commit

Permalink
Merge pull request #58 from CS3219-AY2425S1/dev
Browse files Browse the repository at this point in the history
Dev to main working copy
  • Loading branch information
bhnuka authored Nov 7, 2024
2 parents 0fedbfd + bd5ebe9 commit d175ef3
Show file tree
Hide file tree
Showing 45 changed files with 10,985 additions and 304 deletions.
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 d175ef3

Please sign in to comment.