File tree Expand file tree Collapse file tree 2 files changed +11
-5
lines changed
Expand file tree Collapse file tree 2 files changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -58,8 +58,7 @@ export default defineNuxtModule({
5858 const dbHash = isDev ? 'content' : await database . toHash ( )
5959 const dbName = `db-${ dbHash } .json`
6060 const dbUrl = joinURL ( baseURL , dbFolder , dbName )
61- const dbPath = resolve ( baseDir , dbFolder , dbName )
62- const config = { dbPath, dbUrl }
61+ const config = { dbName, dbUrl }
6362
6463 addPlugin ( resolve ( runtimeDir , 'plugins' , 'db.server' ) )
6564 addPlugin ( resolve ( runtimeDir , 'plugins' , 'db.client' ) )
@@ -96,6 +95,12 @@ export default defineNuxtModule({
9695 nuxt . hook ( 'nitro:config' , async nitroConfig => {
9796 nitroConfig . publicAssets ||= [ ]
9897 nitroConfig . publicAssets . push ( { dir : baseDir } )
98+
99+ nitroConfig . serverAssets ||= [ ]
100+ nitroConfig . serverAssets . push ( {
101+ baseName : 'nuxt-db' ,
102+ dir : buildDir
103+ } )
99104 } )
100105
101106 nuxt . hook ( 'close' , async ( ) => {
Original file line number Diff line number Diff line change 1- import { readFile } from 'fs/promises '
1+ import { useStorage } from 'nitropack/runtime/storage '
22import { defineNuxtPlugin } from '#app'
3- import { dbPath , dbDirs } from '#build/nuxtdb-options'
3+ import { dbName , dbDirs } from '#build/nuxtdb-options'
44import { useDB } from '#imports'
55
66export default defineNuxtPlugin ( async nuxtApp => {
@@ -10,7 +10,8 @@ export default defineNuxtPlugin(async nuxtApp => {
1010 async fetch ( ) {
1111 this . fetchAt = Date . now ( )
1212 try {
13- return JSON . parse ( await readFile ( dbPath , 'utf8' ) )
13+ const storage = useStorage ( 'assets:nuxt-db' )
14+ return await storage . getItem ( dbName )
1415 } catch ( e ) {
1516 console . error ( e )
1617 return [ ]
You can’t perform that action at this time.
0 commit comments