Files
buildpath/frontend/server/utils/mongo.ts
vhaudiquet 599dd1859c
All checks were successful
pipeline / build-and-push-images (push) Successful in 58s
pipeline / deploy (push) Successful in 23s
Added MONGO_URI variable
2025-01-20 15:28:22 +01:00

22 lines
827 B
TypeScript

import { MongoClient } from 'mongodb'
async function connectToDatabase() {
// Create a MongoClient with a MongoClientOptions object to set the Stable API version
let uri = `mongodb://${process.env.MONGO_USER}:${process.env.MONGO_PASS}@${process.env.MONGO_HOST}`
if(process.env.MONGO_URI != undefined && process.env.MONGO_URI != null && process.env.MONGO_URI != "") {
uri = process.env.MONGO_URI
}
const client = new MongoClient(uri)
await client.connect()
return client
}
async function fetchLatestPatch(client : MongoClient) {
const database = client.db("patches");
const patches = database.collection("patches");
const latestPatch = await patches.find().limit(1).sort({date:-1}).next()
return latestPatch!!.patch as string
}
export {connectToDatabase, fetchLatestPatch}