From 2ea40ebb0734ba17428868b4b8ec6ddf2f0dbca0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=98=99=E2=97=A6=20The=20Tablet=20=E2=9D=80=20GamerGirla?= =?UTF-8?q?ndCo=20=E2=97=A6=E2=9D=A7?= Date: Mon, 25 Sep 2023 19:50:07 -0400 Subject: [PATCH] refactor(server/middleware): add middleware to "persist" mongoose's database connection --- server/middleware/00.dbconn.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 server/middleware/00.dbconn.ts diff --git a/server/middleware/00.dbconn.ts b/server/middleware/00.dbconn.ts new file mode 100644 index 0000000..8f498cd --- /dev/null +++ b/server/middleware/00.dbconn.ts @@ -0,0 +1,19 @@ +import mongoose from "mongoose" +import {Ficmas} from "~/models/challenges/ficmas" +import {Challenge} from "~/models/challenges/gen" +import {Biffno} from "~/models/challenges/biffno" + +export default eventHandler(async (event) => { + let beep = useRuntimeConfig() + console.log(beep) + Challenge; + Biffno; + Ficmas; + try { + console.log("connecting........") + await mongoose.connect(beep.database.uri) + } catch(e) { + console.error(e) + throw createError({statusCode: 500, message: "whoops."}) + } +}) \ No newline at end of file