diff --git a/lib/server/plugnplay.ts b/lib/server/plugnplay.ts new file mode 100644 index 0000000..76520c2 --- /dev/null +++ b/lib/server/plugnplay.ts @@ -0,0 +1,20 @@ +import mongoose from "mongoose"; +import { Biffno } from "~/models/challenges/biffno"; +import { Ficmas } from "~/models/challenges/ficmas"; +import { Challenge } from "~/models/challenges/gen"; + +export default async function () { + let beep = useRuntimeConfig(); + Challenge; + Biffno; + Ficmas; + console.log(mongoose.connection.modelNames); + console.log(beep); + try { + await mongoose.connect(beep.database.uri); + // if (!!!mongoose.connections.length) + } catch (e) { + console.error(e); + throw createError({ statusCode: 500, message: "whoops." }); + } +} diff --git a/plugins/01.db.server.ts b/plugins/01.db.server.ts new file mode 100644 index 0000000..3316ee9 --- /dev/null +++ b/plugins/01.db.server.ts @@ -0,0 +1,15 @@ +import mongoose from "mongoose"; +import * as net from "net"; +import plugnplay from "~/lib/server/plugnplay"; +import { Biffno } from "~/models/challenges/biffno"; +import { Ficmas } from "~/models/challenges/ficmas"; +import { Challenge } from "~/models/challenges/gen"; +export default defineNuxtPlugin({ + name: "mongo", + // enforce: 'pre', + async setup(nuxtApp) { + // net.setDefaultAutoSelectFamily(true) + console.log("plugin->connecting........"); + await plugnplay(); + }, +}); diff --git a/server/middleware/00.dbconn.ts b/server/middleware/00.dbconn.ts index 8f498cd..047d229 100644 --- a/server/middleware/00.dbconn.ts +++ b/server/middleware/00.dbconn.ts @@ -1,19 +1,8 @@ -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 +import mongoose from "mongoose"; +import plugnplay from "~/lib/server/plugnplay"; + +export default eventHandler(async (event) => { + console.log("mid->connecting........"); + + await plugnplay(); +});