next/server/plugins/storage.ts

14 lines
455 B
TypeScript
Raw Normal View History

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);
});