refactor(server/middleware): add middleware to "persist" mongoose's database connection

This commit is contained in:
parent 865c648521
commit 2ea40ebb07
Signed by: tablet
GPG Key ID: 924A5F6AF051E87C

@ -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."})
}
})