refactor(server/middleware): add middleware to "persist" mongoose's database connection
This commit is contained in:
parent
865c648521
commit
2ea40ebb07
19
server/middleware/00.dbconn.ts
Normal file
19
server/middleware/00.dbconn.ts
Normal file
@ -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."})
|
||||
}
|
||||
})
|
Loading…
Reference in New Issue
Block a user