diff --git a/modules/tauri/index.ts b/modules/tauri/index.ts index 5c0fec95..9d445922 100644 --- a/modules/tauri/index.ts +++ b/modules/tauri/index.ts @@ -22,6 +22,7 @@ export default defineNuxtModule({ ...nuxt.options.alias, 'unstorage/drivers/fs': 'unenv/runtime/mock/proxy', 'unstorage/drivers/cloudflare-kv-http': 'unenv/runtime/mock/proxy', + '#storage-config': resolve('./runtime/storage-config'), 'node:events': 'unenv/runtime/node/events/index', '#build-info': resolve('./runtime/build-info'), } diff --git a/modules/tauri/runtime/storage-config.ts b/modules/tauri/runtime/storage-config.ts new file mode 100644 index 00000000..2f1ae291 --- /dev/null +++ b/modules/tauri/runtime/storage-config.ts @@ -0,0 +1,2 @@ +export const driver = undefined +export const fsBase = '' diff --git a/nuxt.config.ts b/nuxt.config.ts index e0bd7c8d..266601be 100644 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -1,4 +1,4 @@ -import { createResolver } from '@nuxt/kit' +import { createResolver, useNuxt } from '@nuxt/kit' import Inspect from 'vite-plugin-inspect' import { isCI, isDevelopment, isWindows } from 'std-env' import { isPreview } from './config/env' @@ -86,6 +86,11 @@ export default defineNuxtConfig({ 'postcss-nested': {}, }, }, + appConfig: { + storage: { + driver: process.env.NUXT_STORAGE_DRIVER ?? (isCI ? 'cloudflare' : 'fs'), + }, + }, runtimeConfig: { adminKey: '', cloudflare: { @@ -102,8 +107,7 @@ export default defineNuxtConfig({ defaultServer: 'm.webtoo.ls', }, storage: { - driver: isCI ? 'cloudflare' : 'fs', - fsBase: 'node_modules/.cache/servers', + fsBase: 'node_modules/.cache/app', }, }, routeRules: { @@ -126,6 +130,13 @@ export default defineNuxtConfig({ ignore: ['/settings'], }, }, + hooks: { + 'nitro:config': function (config) { + const nuxt = useNuxt() + config.virtual = config.virtual || {} + config.virtual['#storage-config'] = `export const driver = ${JSON.stringify(nuxt.options.appConfig.storage.driver)}` + }, + }, app: { keepalive: true, head: { diff --git a/server/shared.ts b/server/shared.ts index 37f4b2bd..5a0d97e5 100644 --- a/server/shared.ts +++ b/server/shared.ts @@ -14,29 +14,31 @@ import cached from './cache-driver' // @ts-expect-error virtual import import { env } from '#build-info' +// @ts-expect-error virtual import +import { driver } from '#storage-config' import type { AppInfo } from '~/types' import { APP_NAME } from '~/constants' -const config = useRuntimeConfig() - const fs = _fs as typeof import('unstorage/dist/drivers/fs')['default'] const kv = _kv as typeof import('unstorage/dist/drivers/cloudflare-kv-http')['default'] const memory = _memory as typeof import('unstorage/dist/drivers/memory')['default'] const storage = useStorage() as Storage -if (config.storage.driver === 'fs') { +if (driver === 'fs') { + const config = useRuntimeConfig() storage.mount('servers', fs({ base: config.storage.fsBase })) } -else if (config.storage.driver === 'cloudflare') { +else if (driver === 'cloudflare') { + const config = useRuntimeConfig() storage.mount('servers', cached(kv({ accountId: config.cloudflare.accountId, namespaceId: config.cloudflare.namespaceId, apiToken: config.cloudflare.apiToken, }))) } -else if (config.storage.driver === 'memory') { +else if (driver === 'memory') { storage.mount('servers', memory()) }