-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from CS3219-AY2425S1/dev
Dev to main working copy
- Loading branch information
Showing
45 changed files
with
10,985 additions
and
304 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.