Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

Commit

Permalink
fix: digital ocean mongo connection
Browse files Browse the repository at this point in the history
  • Loading branch information
eddiejaoude committed Oct 14, 2022
1 parent ef40843 commit b335722
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1 +1 @@
MONGODB_URI="mongodb://localhost:27017/linkfree"
LINKFREE_MONGO_CONNECTION_STRING="mongodb://localhost:27017/linkfree"
9 changes: 8 additions & 1 deletion config/mongo.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import mongoose from "mongoose";
import * as fs from "fs";

let hasConnection = false;
const connectMongo = async () => {
if (hasConnection) {
return;
}
try {
await mongoose.connect(process.env.MONGODB_URI);
// DigitalOcean Apps has cert as environment variable but Mongo needs a file path
// Write Mongo cert file to disk
if (process.env.CA_CER) {
fs.writeFileSync("cert.pem", process.env.CA_CERT);
}

await mongoose.connect(process.env.LINKFREE_MONGO_CONNECTION_STRING);
hasConnection = true;
console.log("DB connected");
} catch (err) {
Expand Down

0 comments on commit b335722

Please sign in to comment.