Skip to content

Commit

Permalink
Merge pull request #35 from chingu-voyages/database-connection
Browse files Browse the repository at this point in the history
Connect backend to database
  • Loading branch information
DalySoftware authored Nov 15, 2024
2 parents f9630df + c86c102 commit 4e12a77
Show file tree
Hide file tree
Showing 5 changed files with 249 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/serverBuildDeploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ jobs:
pm2 delete ${{ env.WEB_ROOT}}/src/app.js 2> /dev/null
echo "Starting node server"
PORT=4000 pm2 start ${{ env.WEB_ROOT}}/src/app.js
PORT=4000 DATABASE_CONNECTION_STRING='${{ secrets.DATABASE_CONNECTION_STRING }}' pm2 start ${{ env.WEB_ROOT}}/src/app.js
237 changes: 236 additions & 1 deletion server/package-lock.json

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

3 changes: 2 additions & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"cors": "^2.8.5",
"dotenv": "^16.4.5",
"express": "^4.21.1",
"joi": "^17.13.3"
"joi": "^17.13.3",
"mongoose": "^8.8.1"
}
}
10 changes: 10 additions & 0 deletions server/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import cors from "cors";
import bodyParser from "body-parser";
import dotenv from "dotenv";
import formRouter from "./routes/form.js";
import mongoose from "mongoose";

// load env vars from .env
dotenv.config();
Expand All @@ -17,6 +18,15 @@ app.use(cors());

app.use("/form", formRouter);

app.use("/database-health", async (_, res) => {
try {
await mongoose.connect(process.env.DATABASE_CONNECTION_STRING);
return res.json({ status: "connected" });
} catch (e) {
return res.json({ status: "error", error: e });
}
});

app.use("/", (req, res) => {
return res.json({ message: "Hello team Radiant Minds" });
});
Expand Down
Empty file removed server/src/test.js
Empty file.

0 comments on commit 4e12a77

Please sign in to comment.