From da8b9600040c7cc4193a3242b795ef31727bd005 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: Thu, 4 Jan 2024 20:49:03 -0500 Subject: [PATCH] refactor(server/plugins): add plugin use mongodb as unstorage driver --- server/plugins/storage.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 server/plugins/storage.ts diff --git a/server/plugins/storage.ts b/server/plugins/storage.ts new file mode 100644 index 0000000..7ea1d3b --- /dev/null +++ b/server/plugins/storage.ts @@ -0,0 +1,13 @@ +import mongoDriver from "unstorage/drivers/mongodb"; + +export default defineNitroPlugin(() => { + const storage = useStorage(); + const db = useRuntimeConfig().database; + const driver = mongoDriver({ + connectionString: + process.env.NODE_ENV == "production" ? `mongodb://${db.user}:${db.password}@localhost:27017/${db.name}` : `mongodb://localhost:27017/${db.name}`, + databaseName: db.name, + collectionName: "cache", + }); + storage.mount("", driver); +});